0

So I think I maybe missing something with Ext.Ajax.request();

So I have code that does the following:

Ext.Ajax.request({
   url : 'myurl',
   success : function(){
     alert('success 1');   
   },
   callback : function(){
     alert('callback');
   }

});

Then later I make another ajax call like this:

Ext.Ajax.request({
   url : 'myurl',
   success : function(){
     alert('success 2');   
   }

});

If i don't define a callback function the old one from the first call is still set. So when it runs it still calls the old callback function defined earlier. So I add listeners to the

Ext.Ajax.on('beforerequest', function(c, o, e){
     //The options has all my previous options
});

So I put a break point in here and looked at the options, and if on my second call or any other ajax call after do not override callback or any other options with an emptyFunction() or any other request config the previous values stays. So if on my second call I didn't redefine the success function the first calls success function would still be there. Is there a way to clear all previous options, on the next call? I could just clear them on each new call. But I don't understand why if the calls are unrelated my options from the last call remain?

b3labs
  • 960
  • 1
  • 14
  • 29

1 Answers1

2

As the docs states, Ext.Ajax is a singleton.

If you look at its code, you'll see the the option config will remain between calls.

So I'm afraid to say that you are using it the wrong way. Ideally, you should define what happens upon success or failure with each call.

It does appear though that this will work:

var iAjax = new Ext.data.Connection();
iAjax.request({
    // unique config here.
});
Izhaki
  • 23,372
  • 9
  • 69
  • 107