tags:

views:

33

answers:

2

how to return jquery ajax data to a string?

code like this

var data=$.get("e/as/ajax-dialog.php?do=member", function(data){
 return data;

}); alert(data); ==> [object]

[object] is not what I want

I want the ajax callback html code to data[string].. please help me

thinks a lot

////////////////////////// update ////////////////////////////////////////

My idea is wrong, thank you...

+1  A: 

Put result processing in the success handler

$.get("e/as/ajax-dialog.php?do=member", function(data){
   alert(data);
});

In your example, alert(data) will be executed immediately after http request made and long before response is received.

More examples here:
http://api.jquery.com/jQuery.get/

On question update.
There's an example of synchronous request in jquery docs

var html = $.ajax({
  url: "some.php",
  async: false
}).responseText;

It's also explained there why making synchronous requests is generally bad idea. So, use it on your own risk.

Nikita Rybak
var bodyContent = $.ajax({ url: "script.php", type: "GET", }).responseText;I need the bodyContent to do somethingI want to lik thisthanks Nikita Rybak
LNXA
A: 

In your case it is probably HTML code, just append it to some HTML node in your document and see, it could be jQuery's object wrapper around HTML.

$.get('ajax/test.html', function(data) {
  $('.result').html(data);
});

Also make sure the content-type of "e/as/ajax-dialog.php?do=member" is text/html,

naikus