Skip to content Skip to sidebar Skip to footer

Return Callback Value Outside Callback Function (ajax)

I am trying return callback value outside callback function example: I make the function based in topic: How do I return the response from an asynchronous call? (function (){

Solution 1:

There are two ways to do this, you can use async false but is deprecated and you can always use a promise:

do a function like this:

function ajaxCallback(id){
  return   $.ajax({
    method: "POST",
    url: "../YourUrl",
    data: {  id: id}
  })
}

then call it like this:

if (id != '')//
{
    ajaxCallback(id)
               .done(function( response ) {
                               //do something with your response
                            });
}

Hope it helps

Post a Comment for "Return Callback Value Outside Callback Function (ajax)"