开发者

Simple JsonResult returns parsererror on Jquery ajax method

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, 开发者_如何学Pythonbut 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"}"


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜