PDA

View Full Version : How can I update the view after submitting form using javascript



Venkateswara Rao
18 Oct 2007, 11:32 PM
Hi, is there any option for running javascript thru response of form submittion.

I want to run javascript as part of response, how to achieve this.


the response might looks like this

{success:true}
<script type="text/javascript">
alert('I am arrived');
</script>

any body have any idea,

Advanced Thanks for your help

Animal
19 Oct 2007, 12:56 AM
Use the Form's "afteraction" event. See docs.

crafter
20 Oct 2007, 8:02 AM
Don't get the server to send the alert/

On server:

echo "{'success':true, 'message':'I am arrived'}";

On the front end.


Ext.Ajax.request({
url : url ,
params : params,
waitMsg: 'Loading, please wait...',
method: 'POST',
callback: function ( options, success, reponse ) {
if (success == true) {
article_grid.refresh_grid();
}

},
success: function ( result, request ) {
// eval(result.responseText);
try{
var response = Ext.util.JSON.decode(result.responseText);
if ( response.success == true ) {
Ext.MessageBox.alert('Record Saved', 'Your record has been saved. ' + response.message);
}
else {
Ext.MessageBox.alert('Saved Failed', 'An error has occurred. Therecord has not been saved. '+ response.message);
}

}catch(e){
}

},
failure: function ( result, request) {
var f = Ext.util.Format;
Ext.MessageBox.alert('Server Failed', f.stripTags(result.responseText));
}
});


This prints a message depending on whether you send success or failure from the server, plus any messages. In this case 'success' means you got a response from the server, even if you sent an reponse like {'success':false, 'message':'I have not arrived'}

If there is some other unexpected error, it is called by the 'failure' portion