Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - How to pass multiple callback functions in jQuery ajax

Tags:

jquery

ajax

In JS file have multiple ajax calls,so I would like to call one AJAX call with multiple callback functions.can any one help me how to call multiple AJAX calls.Here is test code,

$.ajax({
  url : url,
  dataType : 'json',
  success : test1(data)
});

$.ajax({
  url : url,
  dataType : 'json',
  success : test2(data)
}); 

It is working fine,can you please help me how we can call both ajax calls in one.

like image 406
Rajasekhar Avatar asked Nov 28 '22 02:11

Rajasekhar


1 Answers

use the promise object returned by ajax

var a1 = $.ajax({ 
    url : url, 
    dataType : 'json', 
    success : test2
})
.done(cb1)
.done(cb2);
a1.done(cb3);
like image 102
Arun P Johny Avatar answered Dec 11 '22 11:12

Arun P Johny