简体   繁体   中英

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. If I use Ajax in jQuery and call directly the service, I get a '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; I don't know how to avoid it in 'POST' calls. 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; 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.

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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