简单的 JsonResult 在 Jquery ajax 方法上返回解析器错误
我正在使用 asp.net mvc2 和 jquery 1.5.2。我假装是在客户端调用控制器中返回 json 数据的特定方法。
实际上,我的客户端对服务器的调用是有效的,但问题是 jquery 无法识别返回的 json。
我不明白我做错了什么!有人可以帮我解决这个问题吗?
控制器方法:
<HttpPost()> _
Function DoStuff(ByVal id As Integer) As JsonResult
Dim retval As JsonResult = Nothing
retval = Json(New xpto With {.P1 = "P1Value"})
Return retval
End Function
JQuery Ajax 调用:
$.ajax({
url: "/DoStuff/5",
type: "POST",
dataType: "json",
async: false,
success: function(data, textStatus, jqXHR) {
alert(textStatus);
},
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
});
处理错误方法时的值:
错误抛出:jQuery1520029581770420782693_1303980789842 未被调用
文本状态:解析器错误
jqXHR.responseText = "{"P1":"P1Value"}"
i'm using asp.net mvc2 with jquery 1.5.2. what i pretend is to make client-side call to a specific method in my controller that returns a json data.
Actually, my client-side call to server is working, but the problem is that jquery doesn't recognize the returned json.
I cannot understand what i'm doing wrong!, can some one helpme with this?
Controller method:
<HttpPost()> _
Function DoStuff(ByVal id As Integer) As JsonResult
Dim retval As JsonResult = Nothing
retval = Json(New xpto With {.P1 = "P1Value"})
Return retval
End Function
JQuery Ajax call:
$.ajax({
url: "/DoStuff/5",
type: "POST",
dataType: "json",
async: false,
success: function(data, textStatus, jqXHR) {
alert(textStatus);
},
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
});
Values when Handles Error method:
errorThrown: jQuery1520029581770420782693_1303980789842 was not called
textStatus: parsererror
jqXHR.responseText = "{"P1":"P1Value"}"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题不在该代码中,工作正常,问题是由标记上的 Sctipt 标记顺序生成的(验证)
错误:
正确:
The problem was not in the on that code, that is working fine, the problem is generated by the Sctipt tag order on the markup (validate)
WRONG:
RIGHT: