JavaScript. Intro to AJAX. XMLHttpRequest

Home » Tutorials » JavaScript » JavaScript. Intro to AJAX. XMLHttpRequest
In this lesson we begin learning ajax – asynchronous Javascript and XML. This technology allows to exchange data without page reload. We’ll discuss ajax in the javascript context and jquery context.
JS has got built-in object XMLHttpRequest, which implements ajax. Don’t worry about XML in object name. XMLHttpRequest perfectly works with json too. For request sending you must configure it.
In php lessons you know, data can be passed with GET or POST HTTP method. There are no body in GET method. Data is a part of url in this case.
Also it’s very important to understand, browser send or get not only data, but also http headers. Headers are additional information for browsers work with data. For example headers have got Content-Type: or server code answer (200 – Ok, or 404 – Not Found).

When you get answer, you must understand, server is not ready to handle your request or it can send your unexpected answer. In example below it is onreadystatrchange event and readyState property and code answer propery (and text status property).

In example above it’s worth mentioning php great works with json. It has hot two methods – json_encode() and json_decode().

In exercise below we made form authorization data sending through XMLHttpRequest with subsequent received answer from php script (php handler).

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

Pin It on Pinterest

Share This