我在REST模式下运行MongoDB并试图通过HTTP请求从MongoDB服务器获取查询结果。以下是我写的简单代码:在JavaScript中发送HTTP请求以从MongoDB获得结果
<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>
但是我无法得到响应。而当我在我获得以下为响应浏览器的地址栏复制并粘贴URL:
{
"offset" : 0,
"rows": [
{ "_id" : { "$oid" : "4d510086ce29000000007d5a" }, "date" : { "$date":60968917800000 } }
],
"total_rows" : 1 ,
"query" : {} ,
"millis" : 0
}
有人可以帮助,告诉我可能是什么问题。
谢谢你的回复。我没有完全得到你留言的第一部分。我有点困惑,但我会研究它,是的,我正在研究jQuery和YUI过去几天。如果你可以请建议我一个来源(除了雅虎开发者网络),从我可以阅读VUI的地方看,这很棒。 – 2011-02-16 17:43:49