jQuery 1.5 AJAX call fails with “invalid label” fo

2019-02-06 13:24发布

I've just upgraded from version 1.4 to version 1.5 of jQuery, and now my AJAX calls always fail with the "invalid label" error.

An example request is:

jQuery.ajax({
    async: false
    , dataType: "json"
    , error: function (xhr, status, error) { ... }
    , success: function (data, status, xhr) { ... }
    , type: "post"
    , url: "ajax/request.asp"
});

On the net I found this error is raised when the returned JSON is not wrapped with jQuery's callback (e.g. jQuery1234({ "something": "abcd" }).

The problem is I'm returning a JSON, not a JSONP (and I state it in the AJAX request), so why I must specify a callback in the returned JSON?

The 1.5 changelog says nothing about this... (Or it's me who can't read?)

Update:

This is an example of a not working JSON:

{
   "esito":"Ok",
   "centriCosto":[
      {
         "id":"1",
         "descrizione":"Colazione"
      },
      {
         "id":"2",
         "descrizione":"Pranzo"
      },
      {
         "id":"3",
         "descrizione":"Cena"
      }
   ]
}

And this is the same callback-wrapped working JSON:

jQuery1502710949228847014_1296739130498({
   "esito":"Ok",
   "centriCosto":[
      {
         "id":"1",
         "descrizione":"Colazione"
      },
      {
         "id":"2",
         "descrizione":"Pranzo"
      },
      {
         "id":"3",
         "descrizione":"Cena"
      }
   ]
})

By the way, Firebug says both of them are valid JSONs (and he's very picky about correctness).

8条回答
Animai°情兽
2楼-- · 2019-02-06 13:50

looks like this is fixed now in v1.6 - had the same issue after upgrading to ver 1.5.1 & after upgrading to 1.6 the issue disappeared.

查看更多
虎瘦雄心在
3楼-- · 2019-02-06 13:52

Here's the solution:

$.post("...", {},
        function(data) {

      // dont forget to add below lines         

         },"json"); 
查看更多
登录 后发表回答