21

Ajax - Asynchronous JavaScript And XML

What does it include? HTML, JavaScript, XML, jQuery?

What is the best way to start learning Ajax? Should I start from the basics of HTML and JavaScript or base my instruction on a particular language or library?

Noruzzaman
  • 11
  • 7

5 Answers5

26

Ajax is, in short, the process of communicating with a webserver from a page, using JavaScript, without leaving the page.

The key things you need to know for this are:

  • The JavaScript needed to make the request and handle the response
  • The server side code needed to receive the request and make the response (unless you are using a service that provides this for you)

The server side of this depends very much on what server side environment you are working with, so there is little useful that is specific that could be said. What can be usually said are what form the responses can take.

  • JSON is a popular approach for sending structured data.
  • XML is another way to send structured data, but has been falling out of favour of late since JSON is, arguably, easier to work with.
  • Chunks of HTML are popular for shoving into pages with innerHTML.
  • Tiny bits of plain text are useful for simple responses.

As for the client side, there are three common approaches:

  • XMLHttpRequest: Well supported and flexible.
  • fetch: A replacement for XHR with a nicer API but more limited browser support.
  • JSONP: A hack to work around the Same Origin Policy rendered obsolete by the introduction of CORS but which you might stumble across from time to time.

I mentioned the Same Origin Policy above. Normally a script isn't allowed to read data from another domain for security reasons. The CORS standard allows you to work around this.

Now for some resources:

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
4

You Need to have knowledge of HTML and Javascript. W3Schools has a Tutorial on Basics which will help You learn. The best way to learn is to put some code and use it. And Moreover now, JQuery ( a javascript library ) , makes learning Ajax more fun and easier. The Website has good documentation and some Sample Ajax code too.

JWhiz
  • 681
  • 3
  • 10
  • 22
2

AJAX = Asynchronous JavaScript and XML.

So basically it is javascript. jQuery among other things simplifies your code sending AJAX requests. HTML is markup, not language and is not related to AJAX.

You may start with this tutorial.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

You need first to understand Javascript and how to program it. On my side, when I first started to develop Javascript, my experience was mainly C, C++, Perl and the like.

Due to that background, it quickly occur to me the need in Javascript to be able to query data from the current page (without any redirection) to the web server dynamically. I then discovered the usual key Ajax object XMLHttpRequest.

I would recommend you to use the "regular" Javascript at first, perform some basic dynamic actions, like time display, moving text (...).

Then you could try to implement a simple program that display the clock value from your server. Because XmlHttpRequest perform a dialog between the web server and the client (browser).

For that you need to have access to a web server (eg Apache). You need to chose what language you will use server side to answer the Xmlhttprequests, e.g. PHP, Perl CGI, etc... You need to have Apache dispatch the page requests to that PHP ... script. The script will have to output the result.

 Browser-Javascript request 

 ==> Web server (eg PHP) 
     to Display the clock =
                          "
 Back to browser        <==

The the javacript code will get that answer and will have to display that result somewhere.

In terms of Book, Javascript 5 by Flanagan is my first choice.

Déjà vu
  • 28,223
  • 6
  • 72
  • 100
-1

By actually using it. Is the best way of learning something. ANY thing!

Ionuț Staicu
  • 21,360
  • 11
  • 51
  • 58