views:

570

answers:

3

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?

+1  A: 

did you get this article in your travels into the great google void?

http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/

he also has many other articles about asp.net and jquery interaction.

Did you try POSTing instead of GETing? as indicated here: http://weblogs.asp.net/scottgu/archive/2007/04/04/json-hijacking-and-how-asp-net-ajax-1-0-mitigates-these-attacks.aspx

Ariel
Yes, I did -- I read a few of his articles, but he seems more focused on how to post a JSON object (though, in a fit of desperation, I did model my request after his - with no luck). I just want a simple Get AJAX call, fired off from link, and then display the returned text in an alert.
dfaivre
I started out with a POST, but then rolled back to a GET to try to simplify things. Same behavior each way.
dfaivre
+5  A: 

I can't believe I figured this out - there is a typo in the jquery-1.3.1*vsdoc.js (its in jQuery.httpData if anyone out there is interested - they define the input parameter as filter, then try to reference it as s, which throws an exception). Oddly, if you use the non *vsdoc version, the typo isn't there.

Looks like they released jQuery-1.3.2 with vsdocs - which doesn't have the typo. So I'd say the answer is to just download the update. (jQuery Download Page)

There went a day of my life... hope this helps someone.

dfaivre
yeah, those types of bugs suck ass. if you update your post with the code that works, then people who find this in the future will see the mistake and the fix in the same context.
Ariel
Updating didn't help me. I still get the error. Did you do anything else in addition?
Cyril Gupta
A: 

http://dev.jquery.com/ticket/4435