Hi there,
here is the code...
<script type="text/javascript">
function ajax_json(){
var hr = new XMLHttpRequest();
var url = "news.json";
hr.open("POST", url, true);
// Set content type header information for sending url encoded variables in the request
hr.setRequestHeader("Content-type", "application/json", true);
// Access the onreadystatechange event for the XMLHttpRequest object
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var data = JSON.parse(hr.responseText);
var results = document.getElementById("results");
//results.innerHTML = data.news2.head +" <br/>Full report: " +data.news2.detail;
results.innerHTML = "";
for(var obj in data){
results.innerHTML += "<strong>"+data[obj].head+"</strong>"+"<br/>" +data[obj].detail+"<br/>";
}
}
}
// Send the data to PHP now... and wait for response to update the status div
hr.send(null); // Actually execute the request
document.getElementById("results").innerHTML = "requesting...";
}
</script>
The above code displays data from json file when url is like this var url = "news.json"; but when I change the Url to
http://mydomain.cpm/news.json it does not display the data. And I am running this file from localhost.
So what is happenning here?
Any help? thanks in advance