How do I execute a javascript after Ajax load?

后端 未结 2 1720
梦谈多话
梦谈多话 2021-01-18 09:17

I need to add a class on after an ajax load. I first give a few elements a class \"ready\" which initiate a css transition. When the link li#menu-item-318 a gets clicked it

相关标签:
2条回答
  • 2021-01-18 10:08

    The way to do this would be use the ajaxcomplete function in jQuery which is called implicitly after the completion of any ajax call.

    The examples in this link should get you started

    .ajaxcomplete() Function

    0 讨论(0)
  • 2021-01-18 10:17

    You can use ajaxComplete():

    $.ajaxComplete(function () {
      // Something to execute after AJAX.
    });
    

    Have this as an example:

    $( document ).ajaxComplete(function( event,request, settings ) {
      $( "#msg" ).append( "<li>Request Complete.</li>" );
    });
    

    As said by Popnoodles, this executes when any AJAX call completes. So if you are looking for executing the code in one particular AJAX call, you need to use the success function.

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