user192936
user192936

Reputation:

JQuery .ajax with Chrome

I get a jQuery AJAX response from localhost with

var ajaxsrc = $.ajax({type:"GET", url: "http://localhost:4540/get.aspx?i=<%=Request.QueryString["i"] %>" ,data:"",dataType: "html"}).responseText;
alert(ajaxsrc);

IE alerts the correct text but Chrome alerts empty strings. When I check with developer console I see that it connects to get.aspx and retrieves data, however cannot handle withing my code.

Any advices?

Upvotes: 0

Views: 753

Answers (2)

James Montagne
James Montagne

Reputation: 78630

If you have to block then use async:false as John posted. Ideally though, you want to keep your AJAX asynchronous. Something like this:

 $.ajax({type:"GET", 
         url: "http://localhost:4540/get.aspx?i=<%=Request.QueryString["i"] %>",                
         data:"",
         dataType: "html"
         success: function(data){
             alert(data);
         }
})

Upvotes: 1

John Flatness
John Flatness

Reputation: 33749

From the jQuery.ajax page:

Note that this usage - returning the result of the call into a variable - requires a synchronous (blocking) request! (async:false)

You need to have async: false in the settings object if you're going to do that kind of assignment with .responseText.

You're probably better off passing a success handler, though...

Upvotes: 1

Related Questions