Podio procfu ajax跨域请求已阻止

时间:2018-08-07 11:24:27

标签: ajax podio

我有运行良好的脚本,并显示了正确的结果(Hello JohnG):

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://procfu.com/exe/hello_world.pf");
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Basic MjI4M***********************"] );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, HTTP_BUILD_QUERY(["name" => "JohnG"]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close ($ch);
print_r ($result);
?>

除了ajax,我需要做同样的事情:

$.ajax({
                url: "https://procfu.com/exe/hello_world.pf",
                type: "POST",
                headers: { "Authorization": "Basic MjI4M******************************" },
                //beforeSend: function(xhr){xhr.setRequestHeader('Authorization', 'Basic MjI4M******************************');},
                data: {"name" : "John" },
                success: function (data) {
                console.log(data);
                },
                error:function(data){
                  console.log(data);
                }
            });

对于此ajax调用,我的状态为401(未授权),并且控制台日志中出现此错误:

跨域请求被阻止:“同源起源”策略禁止读取https://procfu.com/exe/hello_world.pf处的远程资源。 (原因:CORS标头“ Access-Control-Allow-Origin”缺失)。 跨域请求被阻止:同源策略禁止读取https://procfu.com/exe/hello_world.pf处的远程资源。 (原因:CORS请求未成功。)

0 个答案:

没有答案