PDA

View Full Version : How do I get a failure() called on an Ajax request?



Tim Toady
9 Apr 2010, 8:29 AM
Hello,

When I write ajax requests, what do I echo out to have the failure function called? I have tried { success: false} and { failure: true}
It seems to work with success false when I do it from a form submit but not when I try it from an ajax request. I am using 3.1

fay
9 Apr 2010, 8:34 AM
The failure function will be called if there is a server-side request failure, and not if you return success: false. Try out a request with an invalid URI.

Elijah
9 Apr 2010, 8:34 AM
Modify your Ajax call to call some file that does not exist on the server such as noFile.php (which does not exist) then your failure: // will get called

CrazyEnigma
9 Apr 2010, 9:01 AM
If you supply a:


{"success": false}


This means the "server" response has passed. Which will not fire the failure callback, which only fires only when there is a server exception.

What you need to do, in this scenario is to check the success property of the JSON object in success.

Inside your Ext.Ajax.request


success: function (response, options) {

var obj = Ext.decode(response.responseText);
if (obj.success)
{
// Success
}
else
{
// Fail
}
}