我试图从jQuery模式发布到Action,并让该操作返回JSON。不过,我不断收到此错误:资源被解释为文档,但使用MIME类型application/json传输
Resource intepreted as Document but transferred with MIME type application/json
然后我的浏览器重定向到我的行动的URL路径的页面,而仅显示了JSON作为一个字符串。
请注意,我能够发布到我的控制器就好,它是当返回Json(...)被调用,由于某种原因,它重定向到我的发布操作的URL比返回到我的ajax调用。
这里是我的行动:
[HttpPost]
public JsonResult Create(MyModel model)
{
return Json(...);
}
我的JS:
$('form')
.submit(function() {
if ($(this).valid()) {
$.ajax({
url: this.action,
contentType: "application/json; charset=utf-8",
type: "post",
data: $(this).serialize(),
success: function(result) {
console.log(result);
$('#formContent').html(result);
});
}
return false;
});
2016-08-05
RJP