Hello,
I am trying to fetch data from Mongodb, using javascript inside html (running on apache localhost), but it is not working, request.status is never 200, it is always 0. Otherwise, on Chrome is says :
XMLHttpRequest cannot load http://localhost:28017/newdb/newcollection/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
although mozilla/opera don't give this error, but in any case request.status is never 200, and request.responseText is always empty.
here is the javascript code:
<script>
var request = new XMLHttpRequest();
request.withCredentials="true";
request.onreadystatechange = handleReadyStateChange;
request.send();
function handleReadyStateChange() {
if (request.readyState == 4) {
if (request.status == 200) {
document.write(request.responseText);
}
}
}
</script>
Thanks a lot for any kind of suggestion.
Cheers
Irfan