Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to invoke a method from ajax success function?

I've a jQuery with ajax using to fetch some data from a servlet

    <script type="text/javascript">
            $(document).ready(function() {

                $.ajax({
                 url:'ServiceToFetchDocType',
                 type:'post',
                 cache:false,
                 success: function(response){
                 //some data fetched from ServiceToFetchDocType
                 //Need to invoke another method here
}
            });


            </script>

Is it possible to invoke another method inside the success function and get some value? I've very new to jQuery and ajax, any kind of help is appreciated.

like image 645
Zeus07 Avatar asked Jun 13 '17 12:06

Zeus07


People also ask

How do you call a method in ajax?

Approach 1: In this approach, we will use the XMLHttpRequest object to make Ajax call. The XMLHttpRequest() method which create XMLHttpRequest object which is used to make request with server. Syntax: var xhttp = new XMLHttpRequest();

How does success function work ajax?

AJAX success is a global event. Global events are triggered on the document to call any handlers who may be listening. The ajaxSuccess event is only called if the request is successful. It is essentially a type function that's called when a request proceeds.

What triggers ajax success?

What triggers Ajax success? Whenever an Ajax request completes successfully, jQuery triggers the ajaxSuccess event. Any and all handlers that have been registered with the . ajaxSuccess() method are executed at this time.

How do I know if ajax request is successful?

The ajaxStop() method specifies a function to run when ALL AJAX requests have completed. When an AJAX request completes, jQuery checks if there are any more AJAX requests. The function specified with the ajaxStop() method will run if no other requests are pending.


1 Answers

$(document).ready(function() {
  $.ajax({
    url: 'ServiceToFetchDocType',
    type: 'post',
    cache: false,
    success: function(response) {
      /* invoke your function*/
      yourFunction();
    }
  });
});
like image 163
guest Avatar answered Sep 22 '22 13:09

guest