MVC后台返回值直接进入Error里

图片说明
图片说明
代码如上,试了好多方法都没用,就是控制器返回的josn值不报错直接返回到了Error里面,他不返回到success 里面求大佬帮我看看啊

error报什么错了

Here is the code from the stack overflow (https://stackoverflow.com/questions/5980389/proper-way-to-use-ajax-post-in-jquery-to-pass-model-from-strongly-typed-mvc3-vie)
$.ajax({
url: '/home/check',
type: 'POST',
data: JSON.stringify(ai),
contentType: 'application/json; charset=utf-8',
success: function (data.success) {
alert(data);
},
error: function () {
alert("error");
}
});

我看你的jquery 代码是不是应该用 JSON.stringify() 转换成 json format.第二点是: 试一下这个:contentType: 'application/json; charset=utf-8',

还有就是在你的 c# code 试一下这个:return Json(new { success = true, responseText= "Your message successfuly sent!"}, JsonRequestBehavior.AllowGet);

The key is to make sure that success = true and JsonRequestBehavior.AllowGet

没代码就没法调试,只能靠猜了。希望能帮上你。

Try 2:
$.ajax({
url : "AJAX_POST_URL",
type: "POST",
data : formData,
success: function(data, textStatus, jqXHR)
{
//data - response from server
},
error: function (jqXHR, textStatus, errorThrown)
{

}

});
多加几个参数 error: function (jqXHR, textStatus, errorThrown) 然后 output 这些变量 看看是什么结果。既然进入了error 那 textStatus 就不是应该是200 并且 errorThrown 应该能提供些有用的信息

ajax写错了吧。
应该是这样

error:function(data){
...
}