AJ Naidas
AJ Naidas

Reputation: 1434

Ext.Ajax.Request not working in Browser

Ext.Ajax.Request doesn't seem to work on desktop web browsers for me. It works perfectly fine on devices and on the xcode simulators but on desktop web browsers, it calls on the failure method. Here is the code:

// send ajax request
        Ext.Ajax.request({
            url: 'http://testapp.cloudapp.net/index.php/api/accounts/login/',
            method: 'POST',
            params: {
                username: Ext.getCmp('username').getValue(),
                password: Ext.getCmp('password').getValue()
            },
            dataType: 'json',
            success : function(response, request) {
                if(response.responseText == true) {
                    Ext.Msg.alert('validated');

                    // animate to wall view
                    Ext.Viewport.animateActiveItem(targetView, { type : 'fade' } );

                    //destroy Login and Register Views
                    var vwRegister = Ext.ComponentQuery.query('register')[0],
                        vwLogin = Ext.ComponentQuery.query('login')[0];

                    setTimeout( function() {
                        vwRegister.destroy();
                        vwLogin.destroy();
                    }, 2000);
                }
                else {
                    Ext.Msg.alert('invalid user');       
                }
            },

            failure: function(response, request) {
                Ext.Msg.alert('error');
            }
        });

I don't think this has something to do with the "Same-origin policy" because I tried doing the same thing using jQuery's $.ajax function and it worked fine.

Upvotes: 0

Views: 1938

Answers (2)

tabrindle
tabrindle

Reputation: 1874

Though not particularly safe or recommended, you can also start browsers like Chrome in a state that disables web security features, like the same origin policy.

For Windows...

chrome.exe --disable-web-security

For Mac...

Chrome.app --args --disable-web-security

Since I don't particularly enjoy using the terminal every time, you can write a bash script to do it for you, or use automator on a Mac.

Also, ensure the browser isn't already running, or else this will not work.

Upvotes: 1

bwags
bwags

Reputation: 1008

Check your debug console, you most likely will see an error about the same origin policy.

If nothing else try opening chrome with the --disable-web-security option to see if it helps.

See this question for exact syntax.

Good luck, Brad

Upvotes: 1

Related Questions