I'd like to create a simple action link in ASP.Net MVC RC2 using jQuery 1.3.1 - something like this:
<a href="#" onclick="AjaxTest1()">Tester</a>
with the AjaxTest1
function:
function AjaxTest1() {
$.ajax({
url: "Home/Ajax1",
error: function(request, status, error) {
alert("error: " + status + ", " + "\n" +
error + ", " + request.responseText +
request.getAllResponseHeaders());
},
success: function(data, status) {
alert("Finally, it worked!");
},
type: "GET",
dataType: "text",
});
return false;
}
and controller action:
public ActionResult Ajax1()
{
return this.Content("Test Content");
}
All I'm trying to do is return a simple string - but the "error" callback is always called with an error of parseerror
. The XmlHttpRequest has the content string "Test Content" in it - so the controller action is being called and the correct data is being returned. I've tried to set the dataType (to "text", "html", "json"), to use the JsonResult type in the controller, to set the returned content type to "text/plain", to use $.get, $.getJson, etc... nothing works. I feel like I must be missing something very, very simple - especially since google is no help. Ideas?