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 :
so , installed rest api v2 : http://v2.wp-api.org/
enabled cors this:
< ? header ( " access- control-allow -origin : * " ) ; ? >in header.php of theme , inwp-content/plugins/json-api/singletons/api.phpi have try install this: https://wordpress.org/plugins/wp-cors/
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
Post a Comment