当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How to fix "Access Control Allow Origin" error when using AJAX to load XML from URL?

问题描述:

I have the following code, which uses AJAX to load XML from a URL, but using that code alone results in this error: "XMLHttpRequest cannot load. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access."

...Ideas, please?

网友答案:

Try the following

  1. Change the ajax to $.ajax({ url: "/php/phpscript.php",

  2. Change the PHP to echo file_get_contents("http://thegamesdb.net/api/GetGamesList.php?name=".$_GET["term"]);

You likely want to sanitize the $_GET["term"]

If the

分享给朋友:
您可能感兴趣的文章:
随机阅读: