wordpress - enable CORS to call JSON REST from Cordova App -


i'm making app apache cordova ... , need take post wordpress site .

please , before duplicate read points below :

  1. so , installed rest api v2 : http://v2.wp-api.org/

  2. enabled cors this: < ? header ( " access- control-allow -origin : * " ) ; ? > in header.php of theme , in wp-content/plugins/json-api/singletons/api.php

  3. i have try install this: https://wordpress.org/plugins/wp-cors/

  4. call method rest api:

                  jquery.ajax({                  type: "get",                  url: "myurl",                  contenttype: "application/json; charset=utf-8",                  datatype: "json",                  success: function (data, status, jqxhr) {                       alert("suucess");                  }               }); 

the result same , firebug returns me cors locked , can not make demands external ... how fix ??

hi there's no need add theme header, add code below wp-content/plugins/json-api/json-api.php file inside json_api_init() function

   if (isset($_server['http_origin'])) {    header("access-control-allow-origin: *");    header('access-control-allow-credentials: true');        header("access-control-allow-methods: get, post, options");     }      // accept cross domain transfer.    if ($_server['request_method'] == 'options') {    if (isset($_server['http_access_control_request_method']))    header("access-control-allow-methods: get, post, options");             if (isset($_server['http_access_control_request_headers']))    header("access-control-allow-headers:{$_server['http_access_control_request_headers']}");    exit(0);    } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -