jQuery Ajax请求仅在Internet Explorer中返回JSON

|| 我正在使用jQuery Form插件向ASP.NET MVC控制器发出jQuery Ajax请求。 调用工作正常,但是当我解析期望的JSON时,我在Firefox中获得了期望的结果,但是在Internet Explorer中却得到了null。 Ajax调用是这样的:
var options = {
    iframe: true,
    dataType: \'json\',
    success: function (result, status) {
        $.unblockUI();
        _editingEmail = false;

        if (result.Sent === true) {
            ... Do something
        }

        $(\"#messageSentResult\").html(\"<div>\" + result.Message + \"</div>\");
    },
    error: function (xhr, textStatus, errorThrown) {
        $.unblockUI();
        alert(textStatus);
    },
    beforeSubmit: function () {
        $.blockUI({
            message: \'<h1>Processing...</h1>\'
        });
    }
};

$(\'#myForm\').ajaxForm(options);
这是我的控制器:
[HttpPost]
public FileUploadJsonResult MyMethod()
{
    ... Do something

    if(ValidationFails())
    {
        return new FileUploadJsonResult { Data = new { Sent = false, Message = \"The operation was not successful.\" } };
    }

    return new FileUploadJsonResult { Data = new { Sent = true, Message = \"The operation succeeded.\" } };
}
FileUploadJsonResult类如下所示:
public override void ExecuteResult(ControllerContext context)
{
    this.ContentType = \"text/html\";
    context.HttpContext.Response.Write(\"<textarea>\");
    base.ExecuteResult(context);
    context.HttpContext.Response.Write(\"</textarea>\");
}
    
已邀请:
您应该检查HTML页面是否没有错误和警告,并将ajax配置设置为:
$.ajaxSetup({ cache: false });
    
您是否尝试过在选项中设置
cache: false
?默认情况下,除非另有指定,否则IE会缓存
.ajax()
所使用的GET请求。这可能导致您的问题。 编辑: 您是否尝试过将ContentType更改为“ 6”?像这样:
public override void ExecuteResult(ControllerContext context)
{
    this.ContentType = \"application/json\";
    context.HttpContext.Response.Write(\"<textarea>\");
    base.ExecuteResult(context);
    context.HttpContext.Response.Write(\"</textarea>\");
}
    

要回复问题请先登录注册