-1

Ok i have been working in Ajax and when i run it in IE it works fine this is the HTML code:

    <!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","https://www.dropbox.com/s/tq4qhxqtqpgjd57/ajax_info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>

<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

</body>
</html>

the problem is when i run it in Chrome, it gets me this error:

XMLHttpRequest cannot load https://www.dropbox.com/s/tq4qhxqtqpgjd57/ajax_info.txt. Origin file:// is not allowed by Access-Control-Allow-Origin. 

I try using –allow-file-access-from-files but it did not work or maybe i used wrong

also someone can explain me why this error occur?

2 Answers2

0

you should check for the access rights in dropbox settings for that DIR of files.

Uresh Patel
  • 115
  • 9
0

I see that you have already included JQuery to your page. Just use

$('#myDiv').load("https://www.dropbox.com/s/tq4qhxqtqpgjd57/ajax_info.txt");

Using JQuery will let you ignore browser compatibility issues and will make your code more readable.