0

Here's my code :

var request = $.ajax({
    url: 'some.url'    
});
request.done(function(result){
    console.log(result);
});
request.fail(function(result){
    console.log(result);
});

My question is: Is there any way to initiate the same ajax call with just the variable name (In this case it's request) ???

Like: request.SomeMethodToCallSameAjax();

chridam
  • 100,957
  • 23
  • 236
  • 235
Jalay
  • 66
  • 1
  • 7
  • 1
    Try looking at http://stackoverflow.com/questions/8881614/how-do-i-resend-a-failed-ajax-request – William May 02 '14 at 15:21

1 Answers1

1

You can create a function:

var myAjax = function() {
  return request = $.ajax({
     url: 'some.url'    
  });
}

myAjax.done(function(result) { console.log(result); }
myAjax.fail(function(result) { console.log(result); }

When you need to:

//Call my function
myAjax();
alexmngn
  • 9,107
  • 19
  • 70
  • 130
  • Thanks :) That's what I wanted. But I think `myAjax.done()` wont work. Instead there should be `myAjax().done()` – Jalay May 05 '14 at 06:20