$.ajaxSetup() 中的 jquery 解析器错误
我目前正在jquery 中开发一个程序。我的程序在 Firefox 3.5 中运行良好,但直到我将浏览器升级到 Firefox 4.0 后才运行正常。从那时起,“解析器错误”就再也没有出现过,这让我很头疼。
我注意到这是我的代码中第一个“parsererror”显示的部分:
$(document).ready( function() {
...
$.ajaxSetup({
timeout: 10000,
error: function(xhr, msg, e) {
showMessage('HTTP error: ' + JSON.stringify(msg) + '.'); //this is the parsererror
}
});
.
.
})
不仅如此,我的动态选项卡不再出现在我的页面中。我注意到,每次删除此行 '',看起来但我的其他 jquery 元素不好。我不知道出了什么问题。也许是某种不兼容问题,但我只是不知道从哪里开始修复。请帮忙。
编辑: 这是它返回的 json。据推测,这适用于我的动态菜单,它将创建您单击的每个选项卡菜单。但这并没有显示出来。
[
{"title": "File","submenus":[
{"title": "Open","submenus":[]},
{ "title": "New", "submenus":[]},
{ "title": "Save as", "submenus":[]},
{ "title": "Save", "submenus":[]}
]},
{ "title": "View","submenus":[]},
{ "title": "viewAll", "submenus":[]},
{ "title": "Close","submenus":[]},
{"title":"jQgrid", "submenus":[]}
]
i am currently working on a program in jquery. My program works fine in firefox 3.5 but not until i upgraded my browser to firefox 4.0. Since then, the 'parsererror' never failed to show and it gives me a bad headache.
I've notice that this is the part of my code that FIRST 'parsererror' shows:
$(document).ready( function() {
...
$.ajaxSetup({
timeout: 10000,
error: function(xhr, msg, e) {
showMessage('HTTP error: ' + JSON.stringify(msg) + '.'); //this is the parsererror
}
});
.
.
})
And not only that, my dynamic tab no longer appear in my page. I notice that everytime if remove this line '<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
', it appears but my other jquery element is no good. I don't know what's wrong. Maybe it some sort of incompatibility issues, but i just dont where to start fixing. Please help.
EDIT:
this is the json it returned. This is supposedly for my dynamic menu that will create tab Evry menu you clicked. But this doesn't show.
[
{"title": "File","submenus":[
{"title": "Open","submenus":[]},
{ "title": "New", "submenus":[]},
{ "title": "Save as", "submenus":[]},
{ "title": "Save", "submenus":[]}
]},
{ "title": "View","submenus":[]},
{ "title": "viewAll", "submenus":[]},
{ "title": "Close","submenus":[]},
{"title":"jQgrid", "submenus":[]}
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
jQuery Ajax 错误文档的描述
在您的代码中,您可以
查看 jQuery 文档,您将看到第二个参数是一个字符串,而不是您期望的 JSON 对象。解析器正在查看字符串并抛出您所看到的解析错误。
现在,如果发生错误并且对象表示存在错误。 JSON 要求名称用双引号引起来。所以人们认为:
是有效的 JSON,但事实并非如此。以下内容有效。
Description from jQuery Ajax's error documentation
In your code you have
Looking at the jQuery docs, you will see that the second argument is a string and not a JSON object like you are expecting it to be. The parser is seeing the string and throws the parse error that you are seeing.
Now if an error is occurring and the object is saying that there is an error. JSON requires that the name has double quotes around it. So people think:
is valid JSON, but it is not. The following is valid.
听起来上面的代码运行得很好 - 它告诉您 XMLHttpRequest 返回了一个带有消息
“parsererror”
的错误。您可能可以通过检查错误函数中的e
变量来了解更多信息。但您提供的代码不会导致错误,因此我们无法对其进行调试。It sounds like the code above works perfectly - it's telling you that the XMLHttpRequest returned an error with the message
"parsererror"
. You could probably learn more about it by inspecting thee
variable in your error function. But the code you've provided is not causing the error, so there's no way we could debug it.