Wait for .load to finish and then do something

前端 未结 3 1792
暖寄归人
暖寄归人 2020-12-20 11:30

I\'m loading an external script through .load(\'url\') and need to wait for it to finish so I can update the source of an image. Sometimes load is fast enough

相关标签:
3条回答
  • 2020-12-20 11:46

    load method has callback function that is executed when the request completes. I think you should use it.

    0 讨论(0)
  • 2020-12-20 11:53

    Add a callback function:

    $('#yourElement').load('yourUrl.html', function() {
      /* When load is done */
    });
    

    More to read at http://api.jquery.com/load

    0 讨论(0)
  • 2020-12-20 11:56

    Your question is answered here on how to capture the success event of a load function: Checking Jquery ajax load success

    0 讨论(0)
提交回复
热议问题