我正在使用JQuery Form Plugin,但IE 11存在问题,其中" data.Success"因为使用IE Developer Tools跟踪网络流量可以证明响应中存在JSON,所以会回来错误。
我看到一个成功的初始AJAX POST到/ NewClubOpeningTool / ProcessCompose /带有水合JSON响应,但data.Success是假的。
响应:
{"Success":true,"ViewMode":"Prospects","DraftOrSentViewMode":"Draft","NewClubId":21}
在FF和Chrome中运行良好。
任何想法,为什么会发生这种情况以及我可以尝试什么?
//表单设置
@using (Ajax.BeginForm("ProcessCompose", "NewClubOpeningTool", FormMethod.Post, new AjaxOptions { UpdateTargetId = "update_panel" }, new { @enctype = "multipart/form-data", id="ComposeForm" }))
//处理表单提交的控制器操作
[HttpPost]
public ActionResult ProcessCompose(NewClubInviteComposeEmailViewModel compose, IEnumerable<int> Recipients)
{
[...]
return Json(new { Success = success }, "text/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet);
}
//This code lives in the view that has the AJAX form
$(document).ready(function () {
/***********************************************************
Initialize the JQuery Form object
This is how we are able to upload stuff via an AJAX form
*************************************************************/
var options = {
type:'post',
data: $('#ComposeForm').serializeArray(),
datatype: 'json',
url: '/NewClubOpeningTool/ProcessCompose/',
success: function (data) {
if (data.Success) {
alert('Success! We have data.Success!');
$(".dialog").remove();
$("#divInviteContentArea").load("/NewClubOpeningTool/InviteEmail?clubId=" + data.NewClubId + "&viewMode=" + data.ViewMode + "&draftOrSentViewMode=" + data.DraftOrSentViewMode);
} else {
alert('Error! We do not have data.Success!');
}
},
error: function(jqXHR, textStatus) {
alert('Error: ' + textStatus);
}
};
$('#ComposeForm').ajaxForm(options);
/*************************************************************
Prevent the AJAX form from submitting twice
**************************************************************/
$("#ComposeForm").submit(function (e) {
e.preventDefault();
return false;
});
});
答案 0 :(得分:5)
一切都是正确的,但你犯了一个小错误: 即: -
在ajax调用中将datatype:'json'
更改为dataType:'json'
T (上限)。