I always like code examples when I'm looking for the solution to a problem. This post had the same question I had, and trylan provided the answer I needed but for those who come next and would like to see the code that demonstrates his point, here ya go:
Code:
Ext.Ajax.request({
url: 'mypage.asp',
method: "POST",
params: params,
success: function( r, o ){
responseObj = Ext.util.JSON.decode(r.responseText);
alert(responseObj.success);
},
failure: function( r, o ) {
alert( "Submit failed: " + r.responseText );
}
});
So as long as your http request completes, you are going to end up in your success handler of the AJAX request, even if the logic contained in your server side script might still decide the submission was invalid for some reason. Within the AJAX success handler, I'm then decoding the JSON that is being output by my page to determine what I want to do. For now, let's say myapge.asp is returning the following JSON:
Code:
{ success: false, errors: { reason: 'You are not authorized to use this application. Please contact so and so.' }}
then the alert statement above would alert "false", since that's the value of my JSON response's success attribute. Let's say mypage.asp is returning the following JSON:
well then my alert is "true". You can build on this to do whatever you need inside your sucess handler as follows:
Code:
Ext.Ajax.request({
url: 'audit-update.asp',
method: "POST",
params: params,
success: function( r, o ){
responseObj = Ext.util.JSON.decode(r.responseText);
//alert(responseObj.success);
if(responseObj.success == true){
alert("you did something right and the server knows it");
} else {
alert(responseObj.errors.reason)
}
},
failure: function( r, o ) {
alert( "Submit failed: " + r.responseText );
}
});
this assumes the same JSON responses posted above. Hopefully this helps someone!