Introduction to Ajax
Ajax - Asynchronous JavaScript and XML.
Ajax is a web development technique for creating interactive web applications using a combination of XHTML (or HTML) and CSS for marking up and styling information. (XML is commonly used, although any format will work, including preformatted HTML, plain text, JSON and even EBML).
Like DHTML, LAMP, or SPA, Ajax is not a technology in itself, but a term that refers to the use of a group of technologies together
The XMLHttpRequest object is part of a technology called Ajax (Asynchronous JavaScript and XML).
Using Ajax, data could then be passed between the browser and the server asynchronously, using the XMLHttpRequest API, without having to reload the entire web page.
In some Ajax frameworks and in some situations, an IFrame object is used instead of the XMLHttpRequest object to exchange data with the web server.
With the widespread adoption of the XMLHttpRequest object it quickly became possible to build web applications like Google Maps, and Gmail that used XMLHttpRequest to get new map tiles, or new email without having to reload the entire page.
Ajax requests are triggered by JavaScript code; your code sends a request to a URL, and when it receives a response, a callback function can be triggered to handle the response. Because the request is asynchronous, the rest of your code continues to execute while the request is being processed, so it's imperative (緊急的) that a callback be used to handle the response.
Most jQuery applications don't in fact use XML, despite the name "Ajax"; instead, they transport data as plain HTML or JSON (JavaScript Object Notation).
What is the disadvantage of Ajax?
Unfortunately, different browsers implement the Ajax API differently. Typically this meant that developers would have to account for all the different browsers to ensure that Ajax would work universally. Fortunately, jQuery provides Ajax support that abstracts away painful browser differences. It offers both a full-featured
$.ajax()
method, and simple convenience methods such as $.get()
, $.getScript()
, $.getJSON()
, $.post()
, and $().load().
In general, Ajax does not work across domains. For instance, a webpage loaded from example1.com is unable to make an Ajax request to example2.com as it would violate the same origin policy.
As a work around, JSONP (JSON with Padding) uses
<script>
tags to load files containing arbitrary JavaScript content and JSON, from another domain. More recently browsers have implemented a technology called Cross-Origin Resource Sharing (CORS), that allows Ajax requests to different domains.
Does AJAX work with Java?
Absolutely. Java is a great fit for AJAX! You can use Java Enterprise Edition servers to generate AJAX client pages and to serve incoming AJAX requests, manage server side state for AJAX clients, and connect AJAX clients to your enterprise resources. The JavaServer Faces component model is a great fit for defining and using AJAX components.
Reference
http://learn.jquery.com/ajax/
http://www.withoutbook.com/Technology.php?tech=24&page=3&subject=Ajax%20Interview%20Questions%20and%20Answers
https://www.udemy.com/blog/ajax-interview-questions/
No comments:
Post a Comment