I am trying to display data returned as json data. but i am getting returned data as error.
here is my code:
$.ajax({
url:"http://excelonlineclasses.com/test.json",
dataType: "jsonp",
success: function(data){
alert(data.facets.stats.total);
}
});
i have tried $.getJson
but it not works please find fiddle link http://jsfiddle.net/6Yj5h/1680/
please provide me solution. thanks in advance
ne1410s is correct: the URL serves JSON, not JSONP.
You have three choices:
I believe there's a fourth choice, but, honestly, it just gets more hack-ish from here.
To get the server to support CORS, you would want to add some stuff to the header, such as:
Access-Control-Allow-Origin: http://excelonlineclasses.com/
Access-Control-Allow-Methods: GET
Access-Control-Allow-Headers: content-type
Access-Control-Max-Age: 10
...but it doesn't end there. Browsers can send an OPTIONS request (in addition to GET or POST) to find out how the server feels about CORS. The above is really what the server should return in that case.
If you want to set up CORS, I suggest reading something like http://enable-cors.org/
If you get Cross-Origin Request errors then you can set you header to allow cross origin requests In php you can achive this by addin this line of code:
header('Access-Control-Allow-Origin: *');
(but make sure you actually want to enable Cross-Origin Requests- * means from any site! and you know what you are doing. In some cases for security reasons you may not want to allow this)