繁体   English   中英

使用AJAX从URL加载XML时,如何解决“访问控制允许起源”错误?

[英]How to fix “Access Control Allow Origin” error when using AJAX to load XML from URL?

我有以下代码,该代码使用AJAX从URL加载XML,但是单独使用该代码会导致此错误: "XMLHttpRequest cannot load. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access."

...想法,好吗?

尝试以下

  1. 将ajax更改为$.ajax({ url: "/php/phpscript.php",

  2. 将PHP更改为echo file_get_contents("http://thegamesdb.net/api/GetGamesList.php?name=".$_GET["term"]);

您可能希望对$_GET["term"]进行清理

如果

暂无
暂无

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

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