Reputation: 26467
I have a browser-based javascript background and want to get familiar with node.js. As far as I know, node.js is a framework, based on V8 engine, that provides server-side javascript along with some built-in modules.
My question is: does node.js support AJAX calls? And why/how is it done? Of course node can process incomming AJAX request, just as every other server-side technology (python, ruby, php, j2ee) - but I'm asking whether it can fire AJAX calls.
JavaScript is an event-driven technology (asynchronous by nature). Browsers need to fetch external data (from servers), that's why they use XMLHttpRequest
. Because of being server-side, node.js doesn't have to fire AJAX, because it would need to call other servers. If it would need to communicate other server, it could do the same using plain sockets/services just as other technologies do (python, ruby, etc). But, anyway, XMLHttpRequest is built into the browsers, so maybe there could be no reason to remove it from node... Maybe it could be useful somehow.
I'd appreciate an answer that would also explain the topic.
Upvotes: 2
Views: 716
Reputation: 943631
does node.js support AJAX calls?
Ajax is the process of making an HTTP request from a browser, using JavaScript, without leaving the page.
Since Node (in the context of the WWW) usually runs on the server, it doesn't generally do this.
You can:
Because of being server-side, node.js doesn't have to fire AJAX, because it would need to call other servers.
There are plenty of reasons for one server to talk to another one
If it would need to communicate other server, it could do the same using plain sockets/services just as other technologies do (python, ruby, etc).
I can't remember the last time I used Python, Ruby or any other language to get data over a network where I didn't use HTTP (and a prewritten HTTP library).
XMLHttpRequest is built into the browsers, so maybe there could be no reason to remove it from node
Node isn't a browser with bits removed, so XMLHttpRequest hasn't been removed from it, it was never in it in the first place.
There is a built-in HTTP module for Node which can make HTTP requests and several libraries on NPM which provide alternative APIs (including one that implements the XMLHttpRequest specification).
Upvotes: 5
Reputation: 2069
It is not built-in, but there is an NPM module for that: https://www.npmjs.org/package/xmlhttprequest
Upvotes: 1