0

I can’t just use .load() because I’m building a custom loading bar that’s actually truthful about the percentage that has currently been loaded (yes that’s actually possible): http://www.dave-bond.com/blog/2010/01/JQuery-ajax-progress-HMTL5/

I’ve got the loading bar working now but I need to replicate the following jQuery functionality inside the .ajax() function so I can append the #ajaxContent stuff to the .ajaxContainer div once it’s finished loading:

$('.ajaxContainer').load('/path/to/file.php #ajaxContent')
3
  • So, Once the Loading bar finishes (I assume this happens in beforeSend() fucntion, So in success() fucntion you may just append the ajaxStuff to the div (as control comes in success once Ajax callback function (written in php) has returned some value & execution is complete) ) Hope this helps!
    – Domain
    Jul 28, 2015 at 8:12
  • The link you added answers your own question. What's not working exactly ?
    – Pierre
    Jul 28, 2015 at 8:16
  • No it doesn't. It explains how to do the percentage loaded aspect of the functionality. It doesn't explain how to append the content to the page or how to filter the content down to just the piece of html data that you are after. Jul 29, 2015 at 1:29

2 Answers 2

2

The equivalent would be:

$.ajax('/path/to/file.php'/*,{extra: settings}*/).done(function (response) {
    $('.ajaxContainer').html($("<div>").append( $.parseHTML( response ) ).find( '#ajaxContent' ));
});
1
  • I altered it in my code a bit to ensure it definitely wouldn't try to add the the content until the percentage loaded was at 100% (although I'm guessing it probably does that anyway). In terms of answering the question I asked though, this was exactly what I was after :) Jul 29, 2015 at 1:33
1

I think is quite simple to provide a simple answer, I prefer to illustrate you the procedure for retrieve yourself.

If you read the docs of .load() on jQuery site you read:

This method is the simplest way to fetch data from the server. It is roughly equivalent to $.get(url, data, success)

If you read the docs about .get() you read:

This is a shorthand Ajax function, which is equivalent to:

$.ajax({
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

Where dataType

dataType Type: String The type of data expected from the server. Default: Intelligent Guess (xml, json, script, or html).

So in your case you must fill the html element with data from success callback like this:

$('.ajaxContainer').html(response);
1
  • No because OP is using fragment in URL load() parameter
    – A. Wolff
    Jul 28, 2015 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.