Jquery 解析json时出现浏览器问题

Jquery 解析json时出现浏览器问题,jquery,asp.net-mvc,jquery-post,Jquery,Asp.net Mvc,Jquery Post,我正在Asp.NETMVC中开发应用程序 我使用jquery提交表单: var Data = $("#frmForgotPassword").serialize(); $.post("<%= Url.Action("ForgotPassword","Account") %>/", Data, function(retdata, textStatus) { if (textStatus == "success") { if (retdata.status ==

我正在Asp.NETMVC中开发应用程序

我使用jquery提交表单:

var Data = $("#frmForgotPassword").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");

那么错误在哪里呢?如何停止以文件形式打开响应? 它在IE中也给出了同样的错误

编辑:

请求标头:

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

我怀疑这是作为链接上的处理程序调用的,并且您将链接href设置为与AJAX帖子相同的url。如果是这种情况,那么我认为您有一个javascript错误,导致调用链接操作(GET)而不是AJAX post调用。使用Firefox/Firebug检查控制台中是否存在错误

此外,在post方法中,URL的末尾不需要斜杠。查询参数将适当地附加到URL,而不附加它

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

这个怎么样?

启动fiddler--看看您的响应的内容类型是什么。您可以稍微调整一下缩进,这样我们就可以在不滚动的情况下看到整个代码了吗?谢谢用firefox或chrome打开它…我得到了retdata的javascript错误,但是当我打开文件时,文本响应是正确的@Vikas-页面加载时是否存在javascript错误?如果是这样,您的javascript代码没有运行,响应来自单击链接。修复javascript错误,看看它是否开始工作。另外,您可以通过使用操作上的HttpPostAttribute要求请求是post来测试这一点。如果该操作需要一个post,并且它来自GET,您将得到一个异常,即找不到该操作。1。我使用[AcceptVerbs(HttpVerbs.post)],&@将get/post请求分开,每次调用都会执行正确的操作。2.在JavaScript中,我没有看到任何语法错误,当我提交表单frmForgotPassword时,它从服务器提供了正确的json对象,我现在没有看到任何JavaScript错误,但它打开响应的方式不同,如图所示……可能是我在使用jQuery Open dialog函数打开“忘记密码”页面,响应可能会丢失其来源@Vikas-是否从与表单具有相同href的链接打开?是否从链接的单击处理程序返回false?如果您不阻止链接的默认操作,它将同时执行POST和后续GET。在本例中,您将看到get的结果作为文件下载。您能否发布您所展示内容的相关代码,以便我们了解如何调用它?
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
return Json(new {...},JsonRequestBehavior.AllowGet);