I'm learning ASP.NET and I wanted to whip up a simple site that uses ajax to just get a string back from the server.
When I run the ajax request it displays An error occured: 0 error
Here's what I have so far
The controller for the index page with the ajax request on it:
public ActionResult Index()
{
return View();
}
The Controller for the ajax request:
public class AjaxTestController : Controller
{
public ActionResult AjaxAction()
{
return Content(@"Success!");
}
}
the jQuery from the index page:
$( "#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);
}});
});
When I go to http://localhost:49636/AjaxTest/AjaxAction
in my browser it displays Success!
as expected.
Other questions about error 0 say it could have something to do with trying to access a different domain, but I'm not sure that applies here. Any ideas?
Thanks
您是否尝试过将类型更改为“ GET”而不是“ POST”?
您还可以将[HttpPost]
AjaxAction
添加到AjaxAction
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.