Teli Teli - 4 years ago 188
Javascript Question

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

I'm using XAMPP. 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?

Answer Source

Try the following

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

  2. Change the PHP to echo file_get_contents("".$_GET["term"]);

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

If the

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download