Ajax request

Have not done this before. so most likely this is totally wrong. I was having cross referencing issue so I put a simple text file on a server. this is in my .js

var xhttp;
if (window.XMLHttpRequest) {
	xhttp = new XMLHttpRequest();
	} else {
	// code for IE6, IE5
	xhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
				
	xhttp.open("GET", "http://agileart.us/aa-tempbuild/textContent.txt", true);
	xhttp.send();


$("#subSect1").load("http://agileart.us/aa-tempbuild/textContent.txt");

I have this line at the top in the textContxt.txt

Access-Control-Allow-Origin:file:///C:/xampp/htdocs/jsCoding/index.php

So what am I doing wrong? Advice please? Thx

Hi,

You need to get your web server (apache/IIS/etc) configured to send the Access-Control-Allow-Origin header… just putting that at the top of your file won’t work.

http://enable-cors.org/server.html provides instructions on how to configure most web servers to send the header.

If you don’t have access to the server configuration, but you have PHP installed, then it’s possible to send the header from within a script.

textContent.php:

<?php header("Access-Control-Allow-Origin: *"); ?>
// content of your file

Thank you for the advice @fretburner
Will go try it out.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.