Ext.Ajax.Request not working in Browser

2019-08-29 03:39发布

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.

2条回答
做个烂人
2楼-- · 2019-08-29 03:42

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

查看更多
Melony?
3楼-- · 2019-08-29 03:54

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.

查看更多
登录 后发表回答