ASPX網站:MVC2:Ajax調用總是運行在錯誤函數中。爲什麼?怎麼了?
<script type="text/javascript">
function AjaxTest() {
var codeVal = "hello world";
if (codeVal) {
$.ajax({
type: "POST",
url: "CheckAge",
data: { code: codeVal },
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (result) {
alert("in ajax success");
},
error: function() {
alert("error");
}
});
}
}
它的雙重檢查,該JavaScript函數被調用。
控制器:
[HttpPost]
public JsonResult CheckAge(String code)
{
return Json("abc");
}
它結束了一直在阿賈克斯 - 錯誤 - 功能。不管怎樣,控制器功能都不會被調用。爲什麼? 爲什麼我總是出錯? 有什麼不對?
我不認爲你可以指定動作,我想你也必須指定控制器。網址:「{Controller}/{Action}」;試試看。我也認爲你的[HttpPost]需要是[AcceptVerbs(HttpVerbs.Post)]。 – XstreamINsanity 2010-08-26 15:06:12
thx 4你的評論。在所有的combian中測試了「MyController/Index」和[AcceptVerbs(HttpVerbs.Post)] - 沒有工作/解決我的問題。 :-(**注意:** [AcceptVerbs(HttpVerbs.Post)]是MVC風格,相當於MVC2中的[HttpPost](兩個)。 – user415876 2010-08-28 09:30:18