![](/img/trans.png)
[英]JQuery ajax call to MVC action always returns an error when there isn't one
[英]Simple Ajax Call to MVC method always returns error
我对MVC方法有一个非常简单的ajax调用,它总是返回带有空白responseText的错误。 我已经使用ajax多年了,似乎无法弄清楚是什么原因造成的:
这是js代码:
$.ajax({
url: "/Mobile/MyMVCMethod",
data: null,
type: "POST",
dataType: 'html',
success: function (data) {
alert("test");
},
error: function (request, status, error) {
alert(status);
alert(request.responseText);
alert(error);
}
});
这是我的C#:
[HttpPost]
public string MyMVCMethod()
{
return "test";
}
代码将其传递给方法,但返回没有详细信息的错误
我尝试了ActionResult是因为我想返回PartialView,但是由于它不起作用,我试图缩小范围并找出是否仅适用于字符串。 即使C#是这样,这也在发生:
[HttpPost]
public ActionResult MyMVCMethod()
{
return PartialView("MyView");
}
我的观点:
<div>hello world</div>
现在,即使执行了MVC方法,我仍然在Ajax中看到“找不到资源”错误
$.ajax({
url:"Mobile/MyMethod",
method:"post",
datatype:"json"
}).done(function( data ) {
alert( "Data " + data );
});
并确保仅调用普通方法而不是操作结果。然后尝试它可能对您有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.