How can I replace image inside a TD with loading image during Ajax call

前端 未结 2 1119
别跟我提以往
别跟我提以往 2021-01-27 05:00

I have an HTML table. In each cell there is an image followed by some text. Something like this:


  This is a test
         


        
2条回答
  •  面向向阳花
    2021-01-27 05:31

    I believe your question is regarding how to change an image before an AJAX Request and then change it back when the AJAX request is finished.

    Well below is a sample...and here is some reference to the jQuery ajax() method. Note: the ajax() method contains options to declare success, error and complete function that can be executed when the AJAX call is successful, errors out, or is completed (ie after either success or error).

    
      This is a test
    
    

    $("#loadingImg").attr("src", "loading.gif");
    $.ajax({ //other options here
      complete: function () {
      $("#loadingImg").attr("src", "image.gif");  // change image back when ajax request is complete
    } });
    

提交回复
热议问题