Display Ajax loader before load data

前端 未结 2 351
[愿得一人]
[愿得一人] 2020-12-25 08:32

Hello friends i want to show Ajax loader before Data load in particular div but problem is the data is coming dynamically on same page but my script calling data from anothe

相关标签:
2条回答
  • 2020-12-25 09:24

    you can try with following script

    <script>
    function ajax()
    {
        var options = {};
        options.url = '';
        options.type = 'post';
        options.data = '';
        options.dataType = 'JSON'; // type data get from sever
        options.contentType = 'application/json';// type data post to sever
        options.async = false;
        options.beforeSend = function () {
    
        };
    
        options.success = function (data)
        {
    
        };
        options.error = function (xhr, status, err) {
    
            console.log(xhr.responseText);
        };
        $.ajax(options);
    }
    </script> 
    
    0 讨论(0)
  • 2020-12-25 09:32

    you can try with following html -

    <body onload="loadingAjax('myDiv');">
        <div id="myDiv">
            <img id="loading-image" src="ajax-loader.gif" style="display:none;"/>
        </div>
    </body>
    

    and the script -

    <script>
    function loadingAjax(div_id) {
          var divIdHtml = $("#"+div_id).html();
          $.ajax({
               type: "POST",
               url: "script.php",
               data: "name=John&id=28",
               beforeSend: function() {
                  $("#loading-image").show();
               },
               success: function(msg) {
                  $("#"+div_id).html(divIdHtml + msg);
                  $("#loading-image").hide();
               }
          });
    }
    </script> 
    
    0 讨论(0)
提交回复
热议问题