1

I am trying to perform some basic operations with jquery json.

  var urlPath= encodeURIComponent('{"fields":"subject,course,unit,topic,lesson"}');
  $.ajax({

              url : 'http://abcd.org/proficiency.json?data'+urlpath,
              type : 'GET',
              dataType : 'jsonp',
              contentType: "application/json",
              success : function(data) {
              console.log("success");

              },
              error: function (XMLHttpRequest, textStatus, errorThrown) {
              console.log(XMLHttpRequest, textStatus, errorThrown);


   }
    });

The error callback is always triggers

Error... parsererror jQuery15001997238997904205_1298484897373 was not called.

How to fix it?

Thanks for reading..

Anand Rajagopal
  • 1,593
  • 6
  • 24
  • 40
  • Does the server actually return JSONP? Please post an example of the response. – Felix Kling Feb 07 '14 at 05:56
  • @Aaron: Wrong. JSONP and JSON are two different things. – Felix Kling Feb 07 '14 at 05:57
  • Wrong data type. Just remove JSONP – Lal krishnan S L Feb 07 '14 at 05:57
  • Are you sure that's the right URL? – Sterling Archer Feb 07 '14 at 05:59
  • @RUJordan, url is right. – Anand Rajagopal Feb 07 '14 at 06:01
  • @kannan, so wat to add datatype? – Anand Rajagopal Feb 07 '14 at 06:02
  • why are You using contentType: "application/json" ? I think it's not needed. only dataType : 'jsonp', - will work fine. Try this. – Ripa Saha Feb 07 '14 at 06:03
  • http://www.stoimen.com/blog/2009/11/03/ajax-datatypes-in-jquery-format-and-access/ – Lal krishnan S L Feb 07 '14 at 06:12
  • {"content": [{"topic": [{"22920": 0.0003933333333333333},{"22937": 0.14765555555555557},{"22881": 0.0013955555555555555}]}],"message": [],"dateRange": [{}],"paginate": {} } – Anand Rajagopal Feb 07 '14 at 06:24
  • @Felix Kling: server response {"content": [{"topic": [{"22920": 0.0003933333333333333},{"22937": 0.14765555555555557},{"22881": 0.0013955555555555555}]}],"message": [],"dateRange": [{}],"paginate": {} } – Anand Rajagopal Feb 07 '14 at 06:41
  • That's not JSONP, that's JSON. You cannot tell jQuery to expect JSONP if you get JSON. – Felix Kling Feb 07 '14 at 06:42
  • @Felix Kling: i tried with dataType: json my server response is blank . when giving dataType: jsonp server response is {"content": [{"topic": [{"22920": 0.0003933333333333333},{"22937": 0.14765555555555557},{"22881": 0.0013955555555555555}]}],"message": [],"dateRange": [{}],"paginate": {} } – Anand Rajagopal Feb 07 '14 at 06:44
  • @Felix Kling: i need like this then only ajax call will get success jQuery15001997238997904205_1298484897373({"content": [{"topic": [{"22920": 0.0003933333333333333},{"22937": 0.14765555555555557},{"22881": 0.0013955555555555555}]}],"message": [],"dateRange": [{}],"paginate": {} }) – Anand Rajagopal Feb 07 '14 at 08:46
  • @Felix Kling: Its triggering the error **missing ; before statement** {"content": [{"topic": [{"22920": 0.0003933333333333333},{"22937": 0.14765555555555557},{"22881": 0.0013955555555555555}]}],"message": [],"dateRange": [{}],"paginate": {} } – Anand Rajagopal Feb 07 '14 at 08:55

1 Answers1

0

The server is giving back invalid JSON, there is an extra }] and a missing ,. It should be changed to this:

{
    "content": [
        {
            "topic": [
                {
                    "22920": 0.0003933333333333333
                },
                {
                    "22937": 0.14765555555555557
                },
                {
                    "22881": 0.0013955555555555555
                }
            ]
        }
    ],
    "message": [],
    "dateRange": [
        {}
    ],
    "paginate": {}
}
Aziz Shaikh
  • 16,245
  • 11
  • 62
  • 79