So I was trying to fetch some data from my node.js server(using express.js) through jQuery.getJSON()
.
Here's the relevant code:
test.html:
<script>
$.getJSON('/test', function(data, status, xhr){
document.write(data.message);
//console.log(data.message);
});
</script>
server.js:
app.get('/test', function(req, res){
res.json({ message: 'Hello World' });
});
Now, things work fine when just a console.log()
is used but when a document.write()
is issued, the request doesn't complete even though the data is fetched i.e. the browser goes into an indefinite loading state after fetching the data.
The status text sent to the callback reads 'success' so I am guessing there is no error on the ajax side setup.
I'm using jQuery 1.11.1 and node.js 0.13.0.
What could be causing this?