Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将数据发布到页面并获取结果数据(跨域)_Javascript_Php_Jquery_Xmlhttprequest_Cross Domain - Fatal编程技术网

Javascript 将数据发布到页面并获取结果数据(跨域)

Javascript 将数据发布到页面并获取结果数据(跨域),javascript,php,jquery,xmlhttprequest,cross-domain,Javascript,Php,Jquery,Xmlhttprequest,Cross Domain,我正在使用BlackbaudAPI,它说我需要将post数据发送到url以接收我想要的XML数据 参考: 我不太确定该怎么做,所以我使用了jQuery的POST方法并得到了跨域错误: 请求的资源上不存在“Access Control Allow Origin”标头 以下是我用来发送请求的代码: $(document).ready(function() { $.post("https://www.kintera.org/api/Authentication/Login.ashx?accountid

我正在使用BlackbaudAPI,它说我需要将post数据发送到url以接收我想要的XML数据

参考:

我不太确定该怎么做,所以我使用了jQuery的POST方法并得到了跨域错误:

请求的资源上不存在“Access Control Allow Origin”标头

以下是我用来发送请求的代码:

$(document).ready(function() {
$.post("https://www.kintera.org/api/Authentication/Login.ashx?accountid=xxxxx",
        {username: "xxxxxx", password:"xxxxxxx"},function(result) {
            console.log(result);
        });
})
这里有人能指引我正确的方向吗?当我在页面上发布一个简单的php帖子时,会显示xml结果,我不知道如何获得这些信息供自己使用。建议

我遇到的最大问题是跨域错误

编辑: 我明白了。对于任何有同样问题的人,这里是我使用curl的解决方案

$ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, "https://www.kintera.org/api/Authentication/Login.ashx?accountid=xxxxxxx");
  curl_setopt($ch, CURLOPT_POST, TRUE);
  curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('username' => $username,'password' => $password)));

  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  $result = curl_exec($ch);
  $xml = new SimpleXMLElement($result);
  curl_close($ch);
对于,不允许跨域调用XHR(又名.Ajax)。但是有一种方式来处理这个问题。它基本上将JSON数据放在方法名中,方法名可以作为回调进行计算,并在应用程序中提供数据


当使用jQuery时,您可能需要查看一下以开始使用。

在URL中尝试添加
回调=?
的可能重复项不幸的是,我仍然收到一个跨域错误:/Post到您的服务器,允许您的服务器进行登录,传回任何必要的内容。您认为可以详细介绍一下如何做到这一点吗?如何使用服务器执行此操作?谢谢你