Ext.Ajax.Request not working in Browser

江枫思渺然 提交于 2019-12-14 03:17:29

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/17542769/ext-ajax-request-not-working-in-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!