GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||
GeezerVison is showing www.tutorialrepublic.com — JavaScript Ajax - Tutorial Republic JAVASCRIPT BASIC
JS Introduction
JS Getting Started
JS Syntax
JS Variables
JS Generating Output
JS Data Types
JS Operators
JS Events
JS Strings
JS Numbers
JS If…Else
JS Switch…Case
JS Arrays
JS Sorting Arrays
JS Loops
JS Functions
JS Objects
JAVASCRIPT & DOM
JS DOM Nodes
JS DOM Selectors
JS DOM Styling
JS DOM Get Set Attributes
JS DOM Manipulation
JS DOM Navigation
JAVASCRIPT & BOM
JAVASCRIPT ADVANCED
JS Date and Time
JS Math Operations
JS Type Conversions
JS Event Listeners
JS Event Propagation
JS Borrowing Methods
JS Hoisting Behavior
JS Closures
JS Strict Mode
JS JSON Parsing
JS Error Handling
JS Regular Expressions
JS Form Validation
JS Cookies
JS AJAX Requests
JS ES6 Features
JAVASCRIPT EXAMPLES
JAVASCRIPT REFERENCE
Advertisements
JavaScript AjaxIn this tutorial you will learn what Ajax is and how to implement it in JavaScript. What is Ajax?Ajax stands for Asynchronous Javascript And Xml. Ajax is just a means of loading data from the server and selectively updating parts of a web page without reloading the whole page. Basically, what Ajax does is make use of the browser's built-in Ajax has become so popular that you hardly find an application that doesn't use Ajax to some extent. The example of some large-scale Ajax-driven online applications are: Gmail, Google Maps, Google Docs, YouTube, Facebook, Flickr, and so many other applications. Note: Ajax is not a new technology, in fact, Ajax is not even really a technology at all. Ajax is just a term to describe the process of exchanging data from a web server asynchronously through JavaScript, without refreshing the page. Tip: Don't get confused by the term X (i.e. XML) in AJAX. It is only there for historical reasons. Other data exchange format such as JSON, HTML, or plain text can be used instead of XML. Understanding How Ajax WorksTo perform Ajax communication JavaScript uses a special object built into the browser—an All modern browsers (Chrome, Firefox, IE7+, Safari, Opera) support the The following illustrations demonstrate how Ajax communication works:
Since Ajax requests are usually asynchronous, execution of the script continues as soon as the Ajax request is sent, i.e. the browser will not halt the script execution until the server response comes back. In the following section we'll discuss each step involved in this process one by one: Sending Request and Retrieving the ResponseBefore you perform Ajax communication between client and server, the first thing you must do is to instantiate an let request = new XMLHttpRequest();
Now, the next step in sending the request to the server is to instantiating the newly-created request object using the The request.open("GET", "info.txt"); -Or- request.open("POST", "add-user.php");
Tip: The file can be of any kind, like And finally send the request to the server using the request.send(); -Or- request.send(body);
Note: The The GET method is generally used to send small amount of data to the server. Whereas, the POST method is used to send large amount of data, such as form data. In GET method, the data is sent as URL parameters. But, in POST method, the data is sent to the server as a part of the HTTP request body. Data sent through POST method will not visible in the URL. See the chapter on HTTP GET vs. POST for a detailed comparison of these two methods. In the following section we'll take a closer look at how Ajax requests actually works. Performing an Ajax GET RequestThe GET request is typically used to get or retrieve some kind of information from the server that doesn't require any manipulation or change in database, for example, fetching search results based on a term, fetching user details based on their id or name, and so on. The following example will show you how to make an Ajax GET request in JavaScript. ExampleTry this code »
When the request is asynchronous, the The
Note: Theoretically, the The
Please check out the HTTP status codes reference for a complete list of response codes. Here's the code from our "greet.php" file that simply creates the full name of a person by joining their first name and last name and outputs a greeting message. ExampleDownload
Performing an Ajax POST RequestThe POST method is mainly used to submit a form data to the web server. The following example will show you how to submit form data to the server using Ajax. ExampleTry this code »
If you are not using the request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
The Some common request headers are: Note: The Here's the code of our "confirmation.php" file that simply outputs the values submitted by the user. ExampleDownload
For security reasons, browsers do not allow you to make cross-domain Ajax requests. This means you can only make Ajax requests to URLs from the same domain as the original page, for example, if your application is running on the domain "mysite.com", you cannot make Ajax request to "othersite.com" or any other domain. This is commonly known as same origin policy. However, you can load images, style sheets, JS files, and other resources from any domain. Tip: Check out the jQuery Ajax methods for quick and seamless Ajax implementation. The jQuery framework provides very convenient methods to implement Ajax functionality. Advertisements
Advertisements
| ||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |