Ext.Ajax.Request无法在浏览器中运行

时间:2013-07-09 07:48:06

标签: ajax extjs sencha-touch-2

Ext.Ajax.Request对我来说似乎不适用于桌面Web浏览器。它在设备和xcode模拟器上运行得非常好,但在桌面Web浏览器上,它会调用失败方法。这是代码:

// 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');
            }
        });

我不认为这与“同源策略”有关,因为我尝试使用jQuery的$ .ajax函数做同样的事情并且它工作正常。

2 个答案:

答案 0 :(得分:1)

检查调试控制台,您很可能会看到有关同一原始策略的错误。

如果没有别的办法尝试使用--disable-web-security选项打开chrome,看它是否有帮助。

有关确切的语法,请参阅this question

祝你好运,布拉德

答案 1 :(得分:1)

虽然不是特别安全或推荐,但您也可以在禁用网络安全功能的状态下启动Chrome之类的浏览器,例如相同的原始政策。

对于Windows ...

chrome.exe --disable-web-security

对于Mac ...

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

由于我不是每次都特别喜欢使用终端,你可以编写一个bash脚本来为你做,或者在Mac上使用automator。

另外,请确保浏览器尚未运行,否则无效。