PDA

View Full Version : success:false not recognized



bhomass
1 Dec 2007, 11:57 PM
I have code to pick up success or failure from Ajax.request


Ext.Ajax.request({
url:'loadPanel?pagename=editsales&tablename=DetailsLeft',
success: function(response, options){
var response = Ext.util.JSON.decode(response.responseText);
........................
},
failure: function(response){
Ext.MessageBox.alert('Error', 'Load Panel DetailsLeft Failed');
}
});

The server replied with
{success:false, errorInfo:'Context SalesDoc is missing'}

but it got right thru to the success: part. anything wrong with my code or JSON format?

santosh.rajan
2 Dec 2007, 12:31 AM
Ajax.request just returns the response by default. Only form submit evaluates json response.

thejoker101
2 Dec 2007, 7:40 AM
Failure is determined by whether it reached the page successfully or not, not by what was returned as with a form.

tryanDLS
2 Dec 2007, 8:08 AM
At the Ajax Request layer, success is indicated by http code 200-299. failure is all others e.g. 404. The actual json data is not evaluated for success/failure until an object looks at it e.g. form load/submit.

dante
2 Dec 2007, 1:39 PM
Why don't you guys just add this little explanation to the official documentation? /:)
I had the same problem and IMHO others will continue to run into this issue.

Animal
3 Dec 2007, 12:13 AM
But there is absolutely no indication or hint whatsoever that Ext.Ajax should actually examine the returned data, let alone evaluate it as JSON and decide upon anything as a result!!!

Ext.Ajax is written and documented as a transport layer, nothing more. If you want to project your own expectations onto it, you can project anything you like, and it still won't do it.

HartlepoolLad
6 Mar 2008, 5:08 AM
I agree that it should be better documented... I just spent ages trying to work out why it was always calling the success function :-(

Really annoying :-(

dlethe
6 Mar 2008, 5:38 AM
I ran into same problem with JSON, compounded by the fact I use an embedded server program.

You need to insure that the server headers send below, in event success:false ...
HTTP/1.1 409 Conflict
Content-Type: application/json

devnull
6 Mar 2008, 8:58 AM
For those of us that have worked with raw XMLHttpRequest objects in the past, this behavior is obvious (since that is what the success/failure functions map to), but apparently not so to those that are relatively new to webapp programming.

riets003
6 Mar 2008, 12:33 PM
I hit the same behaviour.. Dug into it and solved it.. with some help of posted messages and some digging... took some time but I learned a lot along the way..

:)