extjs 6.01跨源问题 [英] cross origin problems with extjs 6.01

查看:51
本文介绍了extjs 6.01跨源问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用POST表单登录我的后端,该后端可以正常工作。后端接受所有位置(*)

I'm using a POST form to login on my backend which works without any problem. The backend accepts all locations (*)

登录后,我准备获取一些数据,然后阻止跨域请求:同源策略不允许使用backend.test / Statistics / .stat(原因:CORS标头 Access-Control-Allow-Origin与 *不对应)。

After I login, I'm ready to get some data and then I get Cross-Origin-request blocked: the Same Origin Policy doesn't allow thebackend.test/Statistics/.stat (Reason: CORS-header ‘Access-Control-Allow-Origin’ doens't corrspond with ‘*’).

    onLoginClick: function(buttons){

    // this.onLoginSuccess(null,null);
    // return;

        var me = this;
        var loginForm = this.lookupReference('loginForm');
        loginForm.submit({
            url: this.url,
            scope: this,
            success: me.onLoginSuccess,
            failure: me.onLoginFailure,
            waitMsg: 'Validating...'
        });
},

    onLoginSuccess: function (form, action) {

        var me = this;

            // destroy login window (form)
                me.getView().destroy();

        var check =     Ext.Ajax.request({
                        url     : 'http://thebackend.test/Statistics/.stat',
                        scope   : this,
                        withCredentials: true,
                        useDefaultXhrHeader: false,
                        cors: true,
                        params: {
                        entity: 'EmployeePid',
                        action: 'lst'
                    },
                        failure : function(response) {
                            console.log('failure is hit');
                        },
                        success : function(response) {

                        }
                    });

                console.log(check);
   }, ...

但是,当我使用firefox POSTER并模拟所有呼叫时作品:没有跨源问题-完全使用!相同的参数(通过HttpFox验证):

However, when I use firefox POSTER and simulate the call everything works: no cross origin problems - using EXACTLY! the same parameters (verified with HttpFox):

推荐答案

我建议您使用Ext.data.JsonP.request而不是Ext.Ajax.request。

I would suggest you to use Ext.data.JsonP.request instead of Ext.Ajax.request.

JSONP通过Wiki定义

JSONP by definition from wiki


是Web开发人员用于克服了浏览器的同源策略所施加的跨域
限制,该限制限制
访问从源地址(而不是页面
的页面来源)获取的资源

is a technique used by web developers to overcome the cross-domain restrictions imposed by browsers' same-origin policy that limits access to resources retrieved from origins other than the one the page was served by

此处为文档

这篇关于extjs 6.01跨源问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆