JQuery put the result of load() into variable instead of a div

Hey, I have been following a tutorial that shows you how to dynamically load content into a div. I would like to load it into a variable instead of the div. The code they have given is this:


$("#contentArea").load("rpc.php?o="+id+"");

How can I change that so that it loads into a given variable and not into the div “contentArea”?

Thanks.


var content;
$.get('rpc.php?o=' + id, function(data){
    content= data;
});
// Do something with content:
alert(content);

Its what im looking for but some reason doesnt work. The alert says undefined.

Sorry about that. You’ll have to wait until the Ajax is finished:


function doSomethingWithData(data) {
    alert(data);
}

$.get('rpc.php?o=' + id, doSomethingWithData);

Works well as always! Thanks :slight_smile: