php - Server will not return AJAX GET request with CORS enabled -


i'm trying enable external sources make requests server. right i'm testing on personal server hosting through godaddy. issue?

i have following code on page i'm trying make request to

//page.php <?php header("content-type: application/json") header('access-control-allow-origin: *'); header('access-control-allow-methods: get');    include_once 'php_dom/simple_html_dom.php'; include_once 'phpquery.php';   if(isset($_get['item'])){     echo json_encode(array("data" => $_get['item'])); } else{     echo json_encode(array("error"=>"no item provided")); } 

i tried making request (with url, obviously) , i'm not getting back.

$.getjson("http://www.example.com/page.php?item=123&format=json&callback=?", function(data) {     alert(data); }); 

chrome developer shows successful request nothing returned. doing incorrectly?

when use callback=? response handled jsonp. try this:

if(isset($_get['item']) && isset($_get['callback'])){     echo $_get['callback'].'('.json_encode(array("data" => $_get['item'])).');'; } 

...or omit callback-parameter.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -