Returning the html from .ajax call
Posted
by coffeeaddict
on Stack Overflow
See other posts from Stack Overflow
or by coffeeaddict
Published on 2010-04-14T13:35:19Z
Indexed on
2010/04/14
13:43 UTC
Read the original article
Hit count: 231
jQuery
I'm getting undefined for some reason when I try to return the html via the callback function:
function getDataFromUrl(urlWithContent)
{
// jQuery async request
$.ajax(
{
url: urlWithContent,
dataType: "html",
success: function(data) {
return $('.result').html(data);
},
error: function(e)
{
alert('Error: ' + e);
}
});
}
I know I'm getting data back, I see it in firebug in the response and also when I alert out the data, I see the entire page content come up in the alert box.
When I call my function, I am doing the following:
var divContent = getDataFromUrl(dialogDiv.attr("href"));
if(divContent)
dialogDiv.innerHTML = divContent;
when I alert out the divContent (before the if statement) I'm getting undefined. Maybe I'm just going about this wrong on how I'm returning back the data?
I also tried just return data; same thing, I get undefined after the call to this method when set to my variable.
© Stack Overflow or respective owner