开发者

Browser issue with parsing json

I am developing application in Asp.net MVC.

I submit the form with using jquery:

var Data = $("#frmForgotP开发者_如何转开发assword").serialize();
$.post("<%= Url.Action("ForgotPassword","Account") %>/", Data, function(retdata, textStatus) {
    if (textStatus == "success") {
        if (retdata.status == false) {
            $("#error").html('<p class="error">Error: ' + retdata.msg + '</p>');
        }
        else {
            $("#error").html('<div class="clean-ok">Success: ' + retdata.msg + '</div>');
        }
    }
    else
        alert("error: " + textStatus);
}, "json");

But I get the response as file open, shown here.

My controller returns the json as follow:

return Json(new { status = false, msg = "User name or email is not registered with us!" });

or

return Json(new { status = true, msg = "Your username and password has been sent to your email address!" });

So where is the mistake? How to stop opening response as file? It gives the same error in IE also.

EDIT:

Request header:

Host    localhost:16293
User-Agent  Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6
Accept  application/json, text/javascript, */*
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Content-Type    application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With    XMLHttpRequest
Referer http://localhost:16293/Account.aspx/LogOn?ReturnUrl=%2fdefault.aspx
Content-Length  15


I suspect this is being invoked as a handler on a link and that you have the link href set to the same url as the AJAX post. If that's the case, then I think you have a javascript error that is causing the link action (a GET) to be invoked instead of the AJAX post call. Check with Firefox/Firebug and see if there is an error in the console.

Also, you don't need a slash at the end of your URL in the post method. The query parameters will be appropriately appended to the URL without it.


return Json(new {...},JsonRequestBehavior.AllowGet);

How about this?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜