问题
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"}"
回答1:
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:
<script src="/Scripts/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui-1.8.11.custom.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.maskedinput-1.3.min.js" type="text/javascript"></script>
RIGHT:
<script src="/Scripts/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui-1.8.11.custom.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.maskedinput-1.3.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
来源:https://stackoverflow.com/questions/5816126/simple-jsonresult-returns-parsererror-on-jquery-ajax-method