简体   繁体   English

如何通过本地 PHP 文件对远程服务器进行跨域 Ajax 调用

[英]How do I make a cross-domain Ajax call to remote server passing through local PHP file

I need to make a post call to a RDF graph, updating some data.我需要对 RDF 图进行后期调用,更新一些数据。 If I use Ajax in jQuery and call directly the service, I get a 'No 'access-control-allowed-origin' ecc.ecc.'如果我在 jQuery 中使用 Ajax 并直接调用该服务,我会得到“No 'access-control-allowed-origin' ecc.ecc”。 warning in console, but the update is successful.控制台警告,但更新成功。

I know that this worning is due to the same-origin policy, and I 'avoid' it in 'GET' calls using 'jsonp' format;我知道这种磨损是由于同源策略,我在使用“jsonp”格式的“GET”调用中“避免”它; I don't know how to avoid it in 'POST' calls.我不知道如何在“POST”调用中避免它。 After some research online, I found out that client-side the only solution (if you don't have access to the server code, as in my case) is to use an IFrame snippet;经过在线研究,我发现客户端唯一的解决方案(如果您无法访问服务器代码,就像我的情况一样)是使用 IFrame 片段; I can't for many reasons.我不能因为很多原因。

The only solution that remains to me is to make the Ajax call to a local PHP file (as I already do for other reasons) and then from there contact the remote server and make the 'POST' call.剩下的唯一解决方案是对本地 PHP 文件进行 Ajax 调用(因为其他原因我已经这样做了),然后从那里联系远程服务器并进行“POST”调用。

Does anyone know if there are other ways?有谁知道是否还有其他方法? If not, do you have any idea on how to make a cross-domain post call from php?如果没有,您对如何从 php 进行跨域 post 调用有任何想法吗?

header('Access-Control-Allow-Origin: *');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM