Note that there are some explanatory texts on larger screens.

plurals
  1. POXMLHttpRequest to the MongoDB simple rest interface
    primarykey
    data
    text
    <p>I am a beginner in both Ajax and MongoDB. I was hoping to visualize some of the data in my MongoDB using a web browser (which, for the moment, is running on the same host). For this, I thought it might be possible to get the data using XMLHttpRequests. I am running MongoDB with the --rest option and I checked that when I load hxxp://localhost:28017/test_db/ss_test/ on Firefox, I get the proper reply (a JSON document with the data in the ss_test collection of the test_db database). So far, so good.</p> <p>I then wrote the following JavaScript function which I connected to the "onclick" of a button:</p> <pre><code>function makeRequest() { var myrequest = new XMLHttpRequest(); myrequest.onreadystatechange = function() { alert("status=" + myrequest.status + " readyState=" + myrequest.readyState) if (myrequest.status == 200 &amp;&amp; myrequest.readyState == 4) { // ...do something with the response } } myrequest.open("GET", "http://localhost:28017/test_db/ss_test/", true); myrequest.send(); } </code></pre> <p>So, when I load the html file on Firefox, open the console and click on my button, I see that the http request is indeed made, the status code is "HTTP/1.0 200 OK" and a response with Content-Length: 219257 is delivered, which looks great. However, the XMLHttpRequest object does not report the status=200. The alerts that pop up report a constant status of 0 as the readyState progressively becomes 1, 2 and 4 and my if statement is never true.</p> <p>Could anyone please tell me what I am doing wrong? In the beginning I thought it was because my html was loaded on the browser by the file protocol or that I was seeing some same-origin policy related issue, but then I put the html file on a web server on localhost and loaded it from there and nothing changed. Thank you very much for any replies!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload