返回Json语法错误

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:

  1. Get a URL that serves JSONP
  2. Get the server to support CORS (Cross-Origin Resource Sharing)
  3. Write your own server-side script that fetches the data, and then gives it to your script FROM THE SAME DOMAIN AS THE SCRIPT

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)