我正在學習ASP.NET,我想掀起一個簡單的站點,它使用ajax從服務器獲取一個字符串。jQuery AJAX在與ASP.NET站點通信時返回錯誤0
當我運行Ajax請求它顯示An error occured: 0 error
這裏是我到目前爲止
它的控制器與Ajax請求的索引頁:
public ActionResult Index()
{
return View();
}
的控制器ajax要求:
public class AjaxTestController : Controller
{
public ActionResult AjaxAction()
{
return Content(@"Success!");
}
}
jQuery的從索引頁:
$("#submit_button").click(function(event)
{
$.ajax({
type: "POST",
url: "http://localhost:49636/AjaxTest/AjaxAction",
data: "{}",
success:function(result){
alert("Response: " + result);
},
error:function(xhr){
alert("An error occured: " + xhr.status + " " + xhr.statusText);
}});
});
當我去http://localhost:49636/AjaxTest/AjaxAction
在我的瀏覽器,它顯示Success!
預期。
有關錯誤0的其他問題表示它可能與嘗試訪問不同的域有關,但我不確定這適用於此。有任何想法嗎?
謝謝
剛剛嘗試過,結果相同 –
這是我改變了jquery調用。有沒有什麼我必須改變.net方面? –