JSON response from jQuery get raises “Invalid label”

后端 未结 6 1203
日久生厌
日久生厌 2020-12-20 07:10
       $.ajax({
  beforeSend: function(xhr) {
 xhr.setRequestHeader(\'Authorization\', \"Basic YWRtaW46YWRtaW4=\");        
},
   url: \"https://test.com/incident.do         


        
6条回答
  •  再見小時候
    2020-12-20 07:34

    Your response is JSON, which is valid, but that's not what jQuery's looking for. When you specify &callback=? in the URL, jQuery is expecting a JSONP response, which looks different, your response should be

    jsonp1279049933243({
      "records": [
        {
            "service_offering": "",
            "number": "INC0000009"
        },
        {
            "service_offering": "",
            "number": "INC0000010"
        }
      ]
    });
    

    What happens when you specify callback=? is that jQuery generates a name for your success function, in this case jsonp1279049933243, JSONP works by just generating a

    What's effectively happening now is:

    
    

    ...which isn't valid JavaScript. Now of course it's loaded via src=https://test.com/incident.do?JSON&callback=jsonp1279049933243&sysparm_action=getRecords, but the invalid syntax/label error is the same.

提交回复
热议问题