douyi0902 2017-07-10 16:19
浏览 950

CORS:对预检请求的响应未通过访问控制检查:否'Access-Control-Allow-Origin'

I'm trying to login to moodle from an external webpage using a post form to moodle, I used the next ajax to send the inputs:

var frm = $('#loginForm');

frm.submit(function(e) {
    e.preventDefault();
    $.ajax({
        type: frm.attr('method'),
        url: frm.attr('action'),
        data: frm.serialize(),
        xhrFields:{
            withCredentials:true
        },
        async:true,
        beforeSend: function (xhr){
            xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
        },
        success: function (data) {
            console.log("Logged");
        },
        error: function (data) {
            console.log("NOT Logged");
        },
    });
});

Now into the moodle's login/index.php I insert the headers to make possible the CORS connection:

header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: http://fabianmurillo.000webhostapp.com");
header("Origin" : "http://fabianmurillo.000webhostapp.com");

When I run the code, the browser returns an error:

..preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin'.. 

enter image description here

Dunno why browser is blocking the connection for login to moodle.

Thanks for your help.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?