Hello,
I have a problem in loading a (probably) json file from this link:
http://creativescream.com/html5ws/api/news
I try following the guide from W3Schools but I can’t execute it in Chrome nor Safari. My code looks like this:
<html>
<head>
<script type="text/javascript">
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","http://creativescream.com/html5ws/api/news",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>
Now i am very new with this AJAX/JSON buisness and i don’t know if i am missing some steps beside the fact that i find it hard to understand how those two work together. But what i need is to load the link : http://creativescream.com/html5ws/api/news into a HTML page and place the News,Tittle, Author from the link ,anywhere on the page (some div or something).
My only success so far is to load the json from the link in the Internet Explorer 9 and whenever that worked, in Google Chrome and Safari under the web inspectors/console it shows me error “Origin null is not allowed by Access-Control-Allow-Origin.” for Chrom and “Origin file:// is not allowed by Access-Control-Allow-Origin.” for Safari.
I would appreciate a lot if someone could explain me how AJAX works and if i should get that JSON file over it or over JSON, but any help that could help me make this problem work is welcome.
P.S: Sorry if this is not the subject for the forum since it is PHP related, but i didn’t know other place to find help.
Thanks
Dushan