我想從jQuery代碼調用控制器操作方法,但不知何故它不工作。以下是從JavaScript代碼:從jQuery調用ASP.MVC操作方法
$(document).ready(function() {
$("#sendOTPSubmit").click(function() {
$.ajax({
url: 'Controllers/RegisterSurfaceController/SendOTP',
success: function(data) {
alert(data);
},
statusCode: {
404: function(content) {
alert('cannot find resource');
},
500: function(content) {
alert('internal server error');
}
},
error: function(req, status, errorObj) {
// handle status === "timeout"
// handle other errors
}
});
});
});
[HttpPost]
public JsonResult SendOTP()
{
CardHolder user = new CardHolder();
return Json("");
}
我收到以下錯誤:
http://localhost:49289/Controllers/RegisterSurfaceController/SendOTP 404 (Not Found)
$ .ajax({0}} {url:'Controllers/RegisterSurfaceController/SendOTP',輸入:「POST」, – SilentTremor