I am running MongoDB in the REST mode and trying to get query results from the MongoDB server through HTTP request. The following is the simple code that I have written:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function httpGet(theUrl){
//document.write(theUrl);
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", theUrl, false);
xmlHttp.send(null);
document.getElementById("response").innerHTML=xmlHttp.responseText;
}
</script>
<title>Connection</title>
</head>
<body>
<button onclick="httpGet('http://127.0.0.1:28017/test/first/?limit=-1')" >
Click
</button>
<p id="response"> </p>
</body>
</html>
But I am unable to get the response. Whereas when I copy and paste the URL in the address bar of the browser I get following as the response:
{
"offset" : 0,
"rows": [
{ "_id" : { "$oid" : "4d510086ce29000000007d5a" }, "date" : { "$date":60968917800000 } }
],
"total_rows" : 1 ,
"query" : {} ,
"millis" : 0
}
Can someone help and tell me what could be the problem.