Ajax bootloader mapping before boot data

Greetings to friends, I want to show the Ajax loader before loading data in a particular div, but the problem is that the data arrives dynamically on one page, but my script calls data from another file, Script.phpsee my code below

Script

<script>
function loadingAjax(div_id)
{
    $("#"+div_id).html('<img src="ajax-loader.gif"> saving...');
    $.ajax({
        type: "POST",
        url: "script.php",
        data: "name=John&id=28",
        success: function(msg){
            $("#"+div_id).html(msg);
        }
    });
}
</script> 

HTML

<body onload="loadingAjax('myDiv');">


<div id="myDiv"></div>

<div id="xyz"><img src="ss/image/abc.jpg" /></div>


</body>

It works fine, but I want to upload data on one page, please help me

Thanks in advance....

EDIT

I want to show the bootloader before loading data #xyzinto#myDiv

+5
source share
2 answers

you can try with the following html -

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

and 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> 
+16
source

you can try with the following script

<script>
function ajax()
{`enter code here`
    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> 
-1
source

All Articles