[英]Why getting “Invalid JSON” added to my custom error message
Invalid JSON: 无效的JSON:
Error 1 : Non-MDX format found.
Why I am getting the Invalid JSON with my custom error message. 为什么我收到带有自定义错误消息的无效JSON。
My code is given bellow: 我的代码如下所示:
$('#btnCreateView').click(function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: '@Url.Action("Create", "Mdx")',
data: $('form').serialize(),
dataType: "json",
success: function (result) {
alert("View Created Successfuly");
window.location = result.link;
},
error: function (jqXhr, textStatus, errorThrown) {
$('#ErrorMessageField').html(errorThrown);
}
});
})
In your controller action you seem to be returning a partial view: 在控制器操作中,您似乎正在返回部分视图:
return PartialView("Fail");
but in your AJAX request you inidicated 但是您在AJAX请求中建议
dataType: "json",
Obviously this is inconsistent. 显然这是不一致的。 When jQuery attempts to parse the string returned from your controller action back into javascript object it fails because you are not sending JSON, you are sending partial HTML. 当jQuery尝试将控制器操作返回的字符串解析回javascript对象时,由于未发送JSON而失败,而是发送了部分HTML。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.