Show loader on processing script function and not on window refresh - HTML










0















I have the following div:



<div id="main Div" ng-controller="nameController">
<div class="jumbotron" style="width: 900px; background:transparent !important; float:left; margin-top: -75px; padding-bottom: 0px; padding-left: 40px; ">
<form class="form-horizontal" id="uploadForm">
<div class="form-group mb-3 d-lg-flex" style="margin-left:-50px;">
<div class="col-md-12">
<input id="upload" type="file" class="form-control" required="true" style="width:70%; margin-left:150px" placeholder="Upload file" file-model="uploadedFile" accept=".csv"/>
</div>
<div class="form-group" aria-label="file upload">
<input type="submit" class="btn btn-primary" ng-click="doUploadFile()" value="Upload" style="margin-left:-50px;"/>
</div>
</div>
</form>
</div>
</div>


Which will call the following script on submit:



$scope.doUploadFile = function() 

var file = $scope.uploadedFile;
var url = "/uploadfile";

var data = new FormData();
data.append('uploadedfile', file);

var config =
transformRequest: angular.identity,
headers:
'Content-Type': undefined



$http.post(url, data, config)
.then(
function(response)
$rootScope.nameData = response.data;
);
;


and display this div:



<div id="alert_success" role="alert" >
<img src="images/Success.png" width="30" height="30" style="margin-left: 5px;" alt="" hspace="5"/>
<strong>Processed</strong> : Refer to Notes column for Status
</div>


I already have a loader, which will be loading only on page refresh.



$(window).on('load', function() 
$('#loading').hide();
);


I instead want to apply the loader when the script is processing the function and not on windows loader.



Can someone help how to achieve this?










share|improve this question




























    0















    I have the following div:



    <div id="main Div" ng-controller="nameController">
    <div class="jumbotron" style="width: 900px; background:transparent !important; float:left; margin-top: -75px; padding-bottom: 0px; padding-left: 40px; ">
    <form class="form-horizontal" id="uploadForm">
    <div class="form-group mb-3 d-lg-flex" style="margin-left:-50px;">
    <div class="col-md-12">
    <input id="upload" type="file" class="form-control" required="true" style="width:70%; margin-left:150px" placeholder="Upload file" file-model="uploadedFile" accept=".csv"/>
    </div>
    <div class="form-group" aria-label="file upload">
    <input type="submit" class="btn btn-primary" ng-click="doUploadFile()" value="Upload" style="margin-left:-50px;"/>
    </div>
    </div>
    </form>
    </div>
    </div>


    Which will call the following script on submit:



    $scope.doUploadFile = function() 

    var file = $scope.uploadedFile;
    var url = "/uploadfile";

    var data = new FormData();
    data.append('uploadedfile', file);

    var config =
    transformRequest: angular.identity,
    headers:
    'Content-Type': undefined



    $http.post(url, data, config)
    .then(
    function(response)
    $rootScope.nameData = response.data;
    );
    ;


    and display this div:



    <div id="alert_success" role="alert" >
    <img src="images/Success.png" width="30" height="30" style="margin-left: 5px;" alt="" hspace="5"/>
    <strong>Processed</strong> : Refer to Notes column for Status
    </div>


    I already have a loader, which will be loading only on page refresh.



    $(window).on('load', function() 
    $('#loading').hide();
    );


    I instead want to apply the loader when the script is processing the function and not on windows loader.



    Can someone help how to achieve this?










    share|improve this question


























      0












      0








      0








      I have the following div:



      <div id="main Div" ng-controller="nameController">
      <div class="jumbotron" style="width: 900px; background:transparent !important; float:left; margin-top: -75px; padding-bottom: 0px; padding-left: 40px; ">
      <form class="form-horizontal" id="uploadForm">
      <div class="form-group mb-3 d-lg-flex" style="margin-left:-50px;">
      <div class="col-md-12">
      <input id="upload" type="file" class="form-control" required="true" style="width:70%; margin-left:150px" placeholder="Upload file" file-model="uploadedFile" accept=".csv"/>
      </div>
      <div class="form-group" aria-label="file upload">
      <input type="submit" class="btn btn-primary" ng-click="doUploadFile()" value="Upload" style="margin-left:-50px;"/>
      </div>
      </div>
      </form>
      </div>
      </div>


      Which will call the following script on submit:



      $scope.doUploadFile = function() 

      var file = $scope.uploadedFile;
      var url = "/uploadfile";

      var data = new FormData();
      data.append('uploadedfile', file);

      var config =
      transformRequest: angular.identity,
      headers:
      'Content-Type': undefined



      $http.post(url, data, config)
      .then(
      function(response)
      $rootScope.nameData = response.data;
      );
      ;


      and display this div:



      <div id="alert_success" role="alert" >
      <img src="images/Success.png" width="30" height="30" style="margin-left: 5px;" alt="" hspace="5"/>
      <strong>Processed</strong> : Refer to Notes column for Status
      </div>


      I already have a loader, which will be loading only on page refresh.



      $(window).on('load', function() 
      $('#loading').hide();
      );


      I instead want to apply the loader when the script is processing the function and not on windows loader.



      Can someone help how to achieve this?










      share|improve this question
















      I have the following div:



      <div id="main Div" ng-controller="nameController">
      <div class="jumbotron" style="width: 900px; background:transparent !important; float:left; margin-top: -75px; padding-bottom: 0px; padding-left: 40px; ">
      <form class="form-horizontal" id="uploadForm">
      <div class="form-group mb-3 d-lg-flex" style="margin-left:-50px;">
      <div class="col-md-12">
      <input id="upload" type="file" class="form-control" required="true" style="width:70%; margin-left:150px" placeholder="Upload file" file-model="uploadedFile" accept=".csv"/>
      </div>
      <div class="form-group" aria-label="file upload">
      <input type="submit" class="btn btn-primary" ng-click="doUploadFile()" value="Upload" style="margin-left:-50px;"/>
      </div>
      </div>
      </form>
      </div>
      </div>


      Which will call the following script on submit:



      $scope.doUploadFile = function() 

      var file = $scope.uploadedFile;
      var url = "/uploadfile";

      var data = new FormData();
      data.append('uploadedfile', file);

      var config =
      transformRequest: angular.identity,
      headers:
      'Content-Type': undefined



      $http.post(url, data, config)
      .then(
      function(response)
      $rootScope.nameData = response.data;
      );
      ;


      and display this div:



      <div id="alert_success" role="alert" >
      <img src="images/Success.png" width="30" height="30" style="margin-left: 5px;" alt="" hspace="5"/>
      <strong>Processed</strong> : Refer to Notes column for Status
      </div>


      I already have a loader, which will be loading only on page refresh.



      $(window).on('load', function() 
      $('#loading').hide();
      );


      I instead want to apply the loader when the script is processing the function and not on windows loader.



      Can someone help how to achieve this?







      jquery html






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 18 '18 at 10:32







      Mike

















      asked Nov 15 '18 at 17:24









      MikeMike

      224420




      224420






















          1 Answer
          1






          active

          oldest

          votes


















          0














          jQuery has APIs to handle such cases. ajaxStart/ajaxStop functions will handle before and after calls, respectivelly..



          You can configure it pretty easily:



          $(document)
          .ajaxStart(function ()
          //start loader
          )
          .ajaxStop(function ()
          //stop loader
          );


          For more information, check the documentation for ajaxSetup() and this topic for a broader discussion






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53324869%2fshow-loader-on-processing-script-function-and-not-on-window-refresh-html%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            jQuery has APIs to handle such cases. ajaxStart/ajaxStop functions will handle before and after calls, respectivelly..



            You can configure it pretty easily:



            $(document)
            .ajaxStart(function ()
            //start loader
            )
            .ajaxStop(function ()
            //stop loader
            );


            For more information, check the documentation for ajaxSetup() and this topic for a broader discussion






            share|improve this answer



























              0














              jQuery has APIs to handle such cases. ajaxStart/ajaxStop functions will handle before and after calls, respectivelly..



              You can configure it pretty easily:



              $(document)
              .ajaxStart(function ()
              //start loader
              )
              .ajaxStop(function ()
              //stop loader
              );


              For more information, check the documentation for ajaxSetup() and this topic for a broader discussion






              share|improve this answer

























                0












                0








                0







                jQuery has APIs to handle such cases. ajaxStart/ajaxStop functions will handle before and after calls, respectivelly..



                You can configure it pretty easily:



                $(document)
                .ajaxStart(function ()
                //start loader
                )
                .ajaxStop(function ()
                //stop loader
                );


                For more information, check the documentation for ajaxSetup() and this topic for a broader discussion






                share|improve this answer













                jQuery has APIs to handle such cases. ajaxStart/ajaxStop functions will handle before and after calls, respectivelly..



                You can configure it pretty easily:



                $(document)
                .ajaxStart(function ()
                //start loader
                )
                .ajaxStop(function ()
                //stop loader
                );


                For more information, check the documentation for ajaxSetup() and this topic for a broader discussion







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 18 '18 at 11:00









                TicoTico

                2,10522533




                2,10522533





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53324869%2fshow-loader-on-processing-script-function-and-not-on-window-refresh-html%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Barbados

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    Node.js Script on GitHub Pages or Amazon S3