PDA

View Full Version : Timing Problem in Ext.data.Connection - beforerequest



kuisli
3 Dec 2014, 7:13 AM
Hi there
First of all: sorry for my english and second: don't hurt me - i'm a newbie :)

I want to check for different things (e.g. the user-session) while a ExtJS-Ajax/direct-call is done.
If my function returns FALSE - then i will abort all the requests and alert(), then redirect the hole page.

I tried this with a mix of ExtJS and jQuery, so there is no recursion beetwen Ajax-calls if i only use ExtJS-Ajax.



<script type="text/javascript">

// jQuery part -------------------

$(function() { // On document ready

myFunction = function(){
$.post('ajax_info.php',{

}, function(result, status){
if(status != 'success' || result != '1'){
return false;
} else {
return true;

}

});
}
});

// ExtJS part -------------------

Ext.util.Observable.observe(Ext.data.Connection, {
beforerequest: function(conn, response, options) {
if(myFunction() == false){


alert('abort all');
conn.abort();
window.location.href = 'go away here';


}

}
});


</script>

With this Code, the ExtJS-request is always running; also if myFunction() will give me back FALSE. Result from myFunction() comes to late. Think this is a timing problem - and i must do this via callback or so...

Can you help me? Thank you very much in advance!

lumberjack
8 Dec 2014, 12:02 PM
If I'm understanding your inquiry correctly, you'd like to run an asynchronous function, which resolves with a boolean value, each time you're about to make an Ext.Ajax request. The response of this request would be processed by the callback associated with the "beforerequest" event listener, which then halts/allows the pending request to go through. Does that sound accurate?

The framework isn't set up to handle the evaluation of an asynchronous chain in any of the "before____" event listeners. Perhaps the backend methods can be updated to handle whatever preprocessing is taking place in the pre-request function.

Let me know if I can clarify anything.

Thanks,
Brian