I've seen lots of questions and solutions to problems like this but nothing has worked for me. I have this:
function() { $("#bdiv").load("bosses.php #icc10n",function(){ return $("#bdiv").html(); }); }
But it's not working. To clarify, I want to load content into #bdiv
and then return the contents of #bdiv
. But it seems that $("#bdiv").html()
is being returned before the content is loaded even though I've put it in a callback function.
The jQuery load() method is a simple, but powerful AJAX method. The load() method loads data from a server and puts the returned data into the selected element.
The load() method was deprecated in jQuery version 1.8 and removed in version 3.0. Use the on() or trigger() method instead.
jQuery Callback FunctionsJavaScript statements are executed line by line. However, with effects, the next line of code can be run even though the effect is not finished. This can create errors. To prevent this, you can create a callback function.
From what I know, the load event will always fire asynchronously, except if the image is already cached (in some browsers). The only reliable solution is to put the code in a callback like you did.
$("#bdiv").load("bosses.php #icc10n",function(data){ // use the data param // e.g. $(data).find('#icc10n') });
as far as I know you cannot make a return statement in the callback function of a $.ajax(), $.post(), $.get(), etc.. method. You could, however, store the 'data' value in a variable declared outside the function, and then set the value of that variable when the callback function executes. And there is a variety of other options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With