-2

I have a few jQuery.load Requests. But I only want to show the results if all loads are successfull and are ready.

I found "queue" but I'm not sure weather this is the right. http://api.jquery.com/queue/

Does anyone know more than I ?

I tried this now, it doesn't works.

function ShowInfos(Code)
{   
    $.when( asyncLoadInfos(Code) ).then(
        function( status ) {
            alert( status + ", things are going well" );
        },
        function( status ) {
            alert( status + ", you fail this time" );
        },
        function( status ) {
            //Infos einblenden
            ShowGrid();
            alert(status + "Yeah");
        }
        );
}


function asyncLoadInfos(Code)
{
    var dfd = new jQuery.Deferred();

    //Generelle Infos laden
    $('someDiv').load(customerURI, function()
    {
      //Here is some Action, not relevant fot the topic
    });


    $("anootherDiv").load(todoURI, function()
    {
        //Unrelevant Code, too
    });


    $("abc").load(phoneNoteURI, function()
    {

        });

    return dfd.promise();
}
LaMiy
  • 103
  • 7
  • 1
    queue is not the right way to do it. It could work, but it's the wrong tool for the job. What you want are deferred/promise objects. – Kevin B Oct 01 '13 at 17:07
  • I tried it with your idea, but it doesn't work, i get no alert. – LaMiy Oct 01 '13 at 17:24
  • you never resolved the deferred object. each instance of .load would need it's own deferred object that gets resolved on success. – Kevin B Oct 01 '13 at 17:27
  • @Kevin B Thank you, I got it ! :) – LaMiy Oct 01 '13 at 17:41
  • possible duplicate of [jquery : wait until all ajax calls finish then continue](http://stackoverflow.com/questions/3952387/jquery-wait-until-all-ajax-calls-finish-then-continue) – Bergi Mar 01 '14 at 15:33

1 Answers1

1

Jquery.load has a complete function. This way you can check success of your ajax-loading. Read more: here Also, look at the API And the example:

$('#content').load(get_info.php,function(){
alert('Content has been loaded');
});
Community
  • 1
  • 1
AxelPAL
  • 1,047
  • 3
  • 12
  • 19
  • This is clear, but I have more than one jQuery.load() and I want to do something when ALL loads are done. – LaMiy Oct 01 '13 at 17:13
  • If you posted relevant code in your question we would know that you already knew this. – Kevin B Oct 01 '13 at 17:13
  • You can see this information in the first setence "I have a few jQuery.load Requests" I added my Code in the first post now, thank you. – LaMiy Oct 01 '13 at 17:23