jQuery 1.5 AJAX调用失败,并显示"invalid label".用于JSON请求 [英] jQuery 1.5 AJAX call fails with "invalid label" for JSON requests

查看:114
本文介绍了jQuery 1.5 AJAX调用失败,并显示"invalid label".用于JSON请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从jQuery的1.4版升级到1.5版,现在我的AJAX调用始终因无效标签"错误而失败.

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.

一个示例请求是:

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

在网上,我发现当返回的JSON没有用jQuery的回调包装时(例如jQuery1234({ "something": "abcd" }).

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" }).

问题是我返回的是JSON,而不是JSONP(我在AJAX请求中声明了它),所以为什么我必须在返回的JSON中指定回调?

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?

1.5更新日志对此一无所知...(或者是我谁无法阅读?)

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

更新:

这是无法正常工作的JSON的示例:

This is an example of a not working JSON:

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

这是与回调包装相同的工作JSON:

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"
      }
   ]
})

顺便说一句,Firebug说它们都是有效的JSON(他对正确性非常挑剔).

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

推荐答案

好吧,我发现了到底是怎么回事.

Ok, I found out what the hell is happening.

jQuery的验证插件与jQuery 1.5不兼容(请参见一个

jQuery's Validation plug-in is not compatible with jQuery 1.5 (see one and two), removing the plug-in yields to the right behaviour.

如果其他人有此问题,则插件的存储库中有一个修补程序:链接

If someone else has this problem, there's a patch in the plug-in's repository: link

这篇关于jQuery 1.5 AJAX调用失败,并显示"invalid label".用于JSON请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆