PDA

View Full Version : Create a prototype for Ajax request



faik
15 Nov 2010, 2:36 AM
Hi all ,

in my application I need to use an Ajax request many times in several places (extended), so I though to write it in the initScript .
I would like to create a prototype which will be extended with new functions depending on the need (e.g : analyse the response of Ajax Request ).
this is my code :

CatFit.sendAjaxRequest = function(url,params){
//if()
// mask viewport
CatFit.mask(true,'dataReq');

Ext.Ajax.request({
url: url,
params: params,
method: 'POST',
timeout: 300000,
success: function(r){
try{
// decode the JSON resonse
var response = Ext.util.JSON.decode(r.responseText);

}catch (e){
// show error message if response cannot be interpreted
//alert("response");
CatFit.mask(false,'dataReq');
CatFit.showErrorMessage('<?php echo $this->rfTranslate('Error');?>','<?php echo $this->rfTranslate('Server response cannot be interpreted.');?>',e);
return;
}

// show error message if an errro was returned
if(response && response.error){
CatFit.mask(false,'dataReq');
CatFit.showErrorMessage('<?php echo $this->rfTranslate('Error');?>','<?php echo $this->rfTranslate('Server responded an error.');?>',response.error);
return;
}
// here I need a function to analyse data come form response

},
failure: function(r){
// show error message if request fails
CatFit.mask(false,'dataReq');
CatFit.showErrorMessage('<?php echo $this->rfTranslate('Error');?>','<?php echo $this->rfTranslate('Server did not respond.');?>',r.responseText || null);
return;
}
});
};


could someone help me in that .
thanks in advance:)

Animal
15 Nov 2010, 3:10 AM
It's an instance of Ext.data.Connection

faik
23 Nov 2010, 1:58 AM
Thank you for the info :)