Difference between ajax and node.js - ajax

I'm confused about node.js and ajax. Can you guys give me the difference.

The only similarity between AJAX and Node.js is that they are both JavaScript; yet they both serve completely different purposes.
AJAX (short for Asynchronous Javascript and XML) is a client-side technology, often used for updating the contents of a page without refreshing it. Such use can be seen just about everywhere; from Facebook, even to Stack Overflow.
Node.js is server-side JavaScript, used for developing server software. For example, you wouldn't want to develop a database system in client-side JS (since, well, anyone could access the database's credentials obviously), but such a task is possible with Node.js. Node.js doesn't get executed in a browser, but by a server - it's uses are very comparable to Apache/PHP, Ruby on Rails, Django, and the like.
TL;DR: AJAX is for client-side stuff, Node.js for server-side stuff

In easy term, The difference between Node.js and Ajax is that, Ajax (short for Asynchronous JavaScript and XML) is a client side technology, often used for updating the contents of the page without refreshing it. While,Node.js is Server Side JavaScript, used for developing server software. Node.js does not execute in the browser but by the server.

Node is full development environment allowing you to thing normal js cannot not like communicate with databases. Ajax is just a technique to get data or scripts from an external file.

Related

Web-Dev with AngularJS: What kind of server software should I use?

I have a question about the concept:
I was out of the web development practices for ~3-4 years, and now, when I try to return to it and to adopt the last technologies, I am very confused.
In the past, I was used to use JSP/PHP/Java Servlets, or some other technology that processes the page in the server and then sends it to the client. For example (JSP):
<% for (String s : names) { %>
<% =s %>
</br>
<% } %>
If I understand correctly, nowadays, AngularJS should perform the loop on the client, instead of Java on the server, and the data should be achieved by the client in JSON format, using an AJAX call to the server.
Is my understanding correct?
If so - I think that all I need is a server that will enable me to define the AJAX functions - I don't need to mix server code with client code anymore (I.e. I don't need JSP / PHP / Java Servlets / etc.). So are there new simple server technologies that are designated to enables these AJAX calls? Which server technologies are recommended and commonly used for these targets in Java and in Python nowadays?
Yes, your understanding is correct. AngularJS is one option, there are other JavaScript frameworks that work in a similar manner - Angular seems to be the most popular at the moment.
As for the server, you can use pretty much any technology there, the standard is to provide JSON data through RESTful web services.
Node.js with Express is popular (and easy to use), if you want to use JavaScript on the server as well.
If you want to use Java, you can use something like JBoss or Jetty as a server and then expose your services using something like Resteasy as RESTful services. It's fairly easy to add to an existing application.
I recommend that you start with the Angular tutorial, which will go through many of these concepts in great detail. It's a good starting point.
As has been suggested, your back-end server will send a JSON to the client. The client can then render the HTML on the page dynamically using a front-end framework like AngularJS.
It doesn't matter what the back-end language is. However, for best performance, some people recommend that you put an additional back-end layer between your server and the browser where you render your HTML before sending it to the browser. They say this results in better performance and search engine optimization. Node.js works well as a rendering layer, so you might as well simplify your technology stack and use use Node.js for your entire back-end.
Also, server-side rendering is easier to achieve with some front-end frameworks than others. This is one of the reasons React has been trending lately. It's easier to achieve server-side rendering with it.

100% Ajax Websites

I have been looking at Hulu's new website and I am very impressed from a developer's standpoint (as well as a designer's).
I have found that, unless you switch between http/https, you are served content entirely from json requests. That is a HUGE feat to have this level of ajax while maintaining browse back button support as well as allowing each url to be visited directly.
I want to create a website like this as a learning experience. Is there any type of framework out there that can give me this kind of support?
I was thinking I could...
leverage jQuery
use clientside MVVM frameworks like KnockoutJS?
use ASP.NET MVC content negotiation to serve html or json determined by an accept header.
using the same codebase.
use the same template for client side and server side rendering
provide ways to update pagetitle/meta tags/etc.
Ajax forms/widgets/etc would still be used, by I am thinking about page level ajax using json and client side templates.
What do you think? Any frameworks out there? Any patterns I could follow?
It is always best to first build a website without AJAX support, then add AJAX on top of that. Doing this means that:
users without javascript can already access your website
users can already visit any URL directly.
Adding AJAX support can be accomplished by various javascript libraries. So that you can render json content, you will want to look at javascript templating. You will want to use javascript templating even on your server side for when you add AJAX support (file extension .ejs). This will probably require some appropriate libraries to run javascript on the server.
When you add AJAX support, you will want to use the "History.js" library for browser back/forward/history support.
Make no mistake. This is a HUGE project (unless your website only has a few pages). So it is going to take a LONG time to add all the AJAX support to the best possible standard.
to answer your bullet point about using the same template server side as well as client side: check outdust. It was originally developed by akdubya, but has since been adopted and enhanced by linkedin. They use it to render templates on their mobile app client side. Personally I've used it on the server side and it works great.

What methods are there for querying a database from a webpage?

I am fairly new to web development, and I am currently creating a mobile web app with PhoneGap. That is to say, it's done entirely in html and associated technologies, which the app then links up properly to function within whatever OS the device is running.
Portions of this app require me to retrieve data from a database on a remote server. This is an entirely new thing to me, having never done any programming involving networks/connections.
I was recommended to use AJAX for this purpose, but I'd like to be certain I'm making an informed choice. What other options are there for an HTML page to retrieve data from a remote server?
there is no other choice you will have to use ajax ( using jquery for exqmple ) to get your data back from the server ..
the best way ( from my point of view ) is to make sure that your data is retrieved as json or jsonp so that you can handle it easily within your app.
and if you do use jquery ajax remember to configure it to allow external ajax request.

Is it still necessary to check if a visitor's browser supports Ajax?

If I have Ajax code on my website:
1) Is it still necessary to check if a user's browser supports Ajax? Don't they all?
2) if so, is there an non-ActiveX approach to check this? I'd really like to avoid ActiveX as some security filters could flag it as potential malware.
It's not a question of if browsers support 'ajax', this is just a pithy term used to describe the process of a client retreiving data from a server via Javascript, typically asynchronously, and typically using the XMLHttpRequest object.
This object is not defined by IE 5-6, so you have to write code to compensate, or use a library such as jQuery which encapsulates this.
So, what you should be asking is whether your site gracefully degrades if Javascript is not available on the client. i.e. can users still get to the content without Javascript?

How do we do AJAX programming

I have no idea about AJAX programming features. I just know that it is Asynchronous Javascript and XML.
Please help me in knowing about this language.
I have gone through many AJAX tutorials. But none of the programs are running. Why I don't know.
Do we save the file with .HTML extension?
Read:
AJAX Tutorial by W3Schools.
AJAX Programming by Google Code University
To start coding you can get the Ajax Control Toolkit by Microsoft. You should read Ajax Control Toolkit Tutorials to get a grasp of it.
You can use the free Microsoft Visual Web Developer 2010 Express Edition as your IDE.
Aside from the correct responses that the others gave you, judging from your question I think you first need to learn about client-side and server-side code.
Do we save the file with .HTML extension?
Yes and no. You will have an HTML frontend, that for instance contains a button. This will be interpreted from the client's (=user) browser. In fact it may be rendered differently depending on the browser/OS/etc.
Now, you attach some Javascript code to this button. This also runs on the client's browser, and creates a XMLHttpRequest object, either directly or through the use of a library (JQuery & Co.). Note that a library is not necessary to do an AJAX request. It will make your life easier if you do a lot of AJAX calls, but it is not essential.
And here's where the magic happens: the XMLHttpRequest object will call asynchronously (i.e.: without reloading the page) a server-side page. This may be a PHP, ASP, Perl etc etc file that does something on the server, for instance queries a database. This part of the operation is absolutely independent from the client. The user can close the browser before the server-side code finishes to load and the server will not know about it.
Once the server-side code has finished executing it returns to the client with some response data (e.g. a piece of XML, JSON, HTML or whatever you like). Finally the client executes (or not) some other Javascript code in response to this, for example to write on the screen, again with no reloading of the page, something based on what the server has returned.
Maybe I can help you understand AJAX by clarifying the concepts a bit.
Please help me in knowing about this language.
AJAX is not a language, it is a way of using existing techniques to improve the user experience of a web site. The language is Javascript in the browser but you can use any server side technique that you feel comfortable with (ASP.NET, Java, PHP, Ruby etc.)
Do we save the file with .HTML extension?
Well, that is not really the point. What you have to grasp here is that there is a server and a browser that interact with each other. Yes, you can use static HTML files for your pages (and save them as .html files), but you'll need a server to respond to the requests of the browser. This may be why your sample code is not working; you need to set up a server that works with your pages.
The whole idea behind AJAX is to improve the user experience by not reloading the entire page when a user interacts with it. You request the data you need and update the page by using Javascript to update the HTML. This is called an out-of-band or asynchronous request.
I just know that it is Asynchronous Javascript and XML.
That is what the acronym stands for but it doesn't quite cover what the technique is for, nor is it accurate any more. In the beginning XML was used to transfer data from the server to the client. People found that XML is not really that easy to work with in Javascript so now it's more common to use JSON. JSON is a snippet of javascript that can be evaluated in the browser. The snippet creates javascript object(s) that represent the data.
If you use a Javascript library, like others have suggested here, you won't have to worry about many of the details though.
Before you get into AJAX you should make sure that you understand:
HTML and CSS
Javascript
how to modify HTML with Javascript
how a browser requests information from a server
how to handle requests on the server
If you are not comfortable with all of these concepts, stick with 'regular' web pages and try to improve your knowledge step by step.
Once you get the basic knowledge from W3school, I suggest you use a framework. Usually developers do not use XMLHttpRequest at all. Instead, javascript frameworks like ExtJS, jQuery and other frameworks make your work simple. I suggest you learn bit of javascript as well. check out jQuery.
Just to add that AJAX is rarely used in its pure form with XMLHttpRequest. You will often use it as a part of AJAX UI libraries which make your life easier. If you are from the Java world - such an AJAX library is Richfaces.
Instead of worrying about how to do AJAX, use something that allows you to forget about it. Frameworks like NOLOH do AJAX (and Comet) for you automatically without you having to do a thing. Just concentrate on your application, and business logic and it does the rest.
Really, everything is done via AJAX if available, automatically. No work on your part. If you're don't want to spend much time researching it, check out this short video that was demonstrated at Confoo PHP Conference this past March http://www.youtube.com/phpframework#p/u/11/cdD9hSuq7aw.
For all those worried about, well, if it's all AJAX, what about search engines? No need to worry, http://dev.noloh.com/#/articles/Search-Engine-Friendly/.
So instead of having to worry about all these different technologies, or the client-server relationship, you can sit down, code and have your website/WebApp working in no time.
You can read about NOLOH is this month's cover story of php|architect magazine, http://www.phparch.com/magazine/2010/may/.
Enjoy.
Disclaimer: I'm a co-founder of NOLOH.
It is easy one. Ajax getting data from server side by client side execution. We have to do use XMLHttpRequest to get the result.

Resources