Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery JSON.parse: unexpected end of data
    primarykey
    data
    text
    <p>I am having some noobist problems with jQuery on a simple example I try to run. The firefox tools give a <code>Syntax Error: JSON.parse: unexpected end of data</code> and I really can't find a way to debug it.</p> <p>I have populated my mongodb with the data below and they do look verified.</p> <pre><code>var employees = [ {"id": 1, "firstName": "James", "lastName": "King", "managerId": 0}, {"id": 2, "firstName": "Julie", "lastName": "Taylor", "managerId": 1}, {"id": 3, "firstName": "Eugene", "lastName": "Lee", "managerId": 1}, {"id": 4, "firstName": "John", "lastName": "Williams", "managerId": 1} ]; </code></pre> <p>and I am trying to return it with</p> <pre><code>exports.findAll = function(req, res) { var name = req.query["name"]; db.collection("employees", function(err, collection) { if (name) { collection.find({"fullName": new RegExp(name, "i")}).toArray(function(err, items) { console.log(items); res.jsonp(items); }); } else { collection.find().toArray(function(err, items) { console.log(items); res.jsonp(items); }); } }); }; </code></pre> <p>and read it on the browser with</p> <pre><code>$.get("http://localhost:8888/employees",function(jsonp){ //document.write("json"); }); </code></pre> <p>EDIT: Using the url on the browser returns valid data, however, for the same action the console.log returns invalid data. This is what makes me suspect a double parsing issue, if there is anything like that.</p> <pre><code>browser-&gt; { "id": 4, "firstName": "John", "lastName": "Williams", "managerId": 1, "_id": 5276247a3f2e4cf040000004 } console-&gt; { id: 4, firstName: 'John', lastName: 'Williams', managerId: 1, _id: 5276247a3f2e4cf040000004 } </code></pre>
    singulars
    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.
 

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