Check if there was POST with Javascript

2

I have a singlepage application, and I would like to monitor POST for a webservice.

When I send the information it removes the loading.

ex:

scope.deleteFile = function (fileId,index) {
                scope.loading = true;
                imageHandler.remove(scope.contentId, fileId);
                scope.attachments.splice(index, 1);
            };

This is where I left off, but loading is true and would like to know when or what jquery or javascript native function I can use to check if the post is complete and after that give a scope.loading = false;

    
asked by anonymous 18.11.2014 / 15:52

3 answers

2

If you are using jQuery to make Ajax calls to the server, you can use ajaxStart and ajaxComplete to execute your logic whenever an Ajax request is started or terminated.

Example:

$(document).ajaxComplete(function(event, xhr, settings){
    console.log(settings.type);
    if(settings.type == "POST"){
        console.log("Foi um POST que acabou.");
    }
});
    
18.11.2014 / 19:36
1

If you're using jQuery, you can add a custom header to all Ajax requests, using the following script syntax loaded shortly after loading jQuery:

<script>
jQuery.ajaxSetup({headers: {"X-Requested-With":"XMLHttpRequest", "X-Ajax" : "1"}});
</script>

And you can access these values in the PHP controller by accessing $_SERVER

    
19.11.2014 / 13:35
1

If you are using angularJS, I recommend the use of angular-block-ui, which alone controls the loading of requests.

link

    
19.11.2014 / 13:47