zuriosam
zuriosam

Reputation: 115

Ajax request in extjs fires success although response is false

I have an AJAX request like:

        Ext.Ajax.request({
            url: 'login.php',
            scope: me,
            params: {
              email: '[email protected]',
              password: '12345',
            },
            
            success: function(){console.log('OK');}, 
            failure: function(){console.log('ERROR');},   
            
        }); 

The console.log is 'OK', even though the response is false

enter image description here

Upvotes: 0

Views: 597

Answers (2)

GordonH
GordonH

Reputation: 15

The success callback function has two return arguments, the first is the response from the server. Decoding the response will allow you to check for a successful login, something like this:

success: function(response, opts) {
    var obj = Ext.decode(response.responseText);
    if (obj.success === true) console.log('success!');
}

Upvotes: 1

norbeq
norbeq

Reputation: 3076

The failure callback fires only if an HTTP status returned from the server is different than 200 OK.

Change the status in response or check the value of success parameter just in success callback.

Upvotes: 2

Related Questions