An introductory tutorial on AJAX reading data

Source: Internet
Author: User
Tags http request xml example xpath xslt

Ajax is "asynchronous Web Effects and XML" (Asynchronous JavaScript and XML), AJAX is not an acronym, but a noun created by Jesse James Gaiiett, a Web development technology that creates interactive Web applications


The most important and most overlooked of the Ajax concepts is that it is also a JavaScript programming language. JavaScript is an adhesive that integrates the parts of an AJAX application. Most of the time, JavaScript is often considered by the server-side developer as an enterprise-class application that should be avoided as much as possible. This view comes from the previous experience of writing JavaScript code: a complex and error-prone language. Similarly, it is also thought to spread the application logic arbitrarily across both the server and the client, making the problem difficult to discover and code difficult to reuse. In Ajax, JavaScript is used primarily to pass data from the user interface to the server and return results. The XMLHttpRequest object is used to respond to data passed over HTTP, and once the data is returned to the client, it is immediately possible to use the DOM to place the data on the network surface.
XMLHttpRequest
The XMLHttpRequest object is implemented on most browsers and has a simple interface that allows data to be delivered from the client to the server, but does not interrupt the user's current operation.   Data transmitted using XMLHttpRequest can be in any format, although it is suggested from the first name as XML-formatted data. Developers should already be familiar with many other XML-related technologies. XPath can access data in an XML document, but it is necessary to understand the XML DOM. Similarly, XSLT is the simplest and fastest way to generate HTML or XML from XML data. Many developers are already familiar with XPath and XSLT, so it makes sense for Ajax to choose XML as the data Interchange format. XSLT can be used on both the client and the server side, and it can reduce the number of application logic written in JavaScript.
CSS Tutorials
CSS is an important weapon that Ajax developers need to navigate to the right AJAX application. CSS provides a mechanism for separating application styles and designs from content. Although CSS plays a crucial role in AJAX applications, it is also a major impediment to building cross-browser applications because different browser vendors support a variety of CSS levels.
Server-side
But unlike on the client side, AJAX applications at the server end are based on mechanisms such as java,.net and PHP tutorial language, and there is no change in the main approach in this area. That being the case, our interest in the Ruby o n rails framework has increased rapidly. More than a year ago, Ruby O-N rails had attracted a large number of developers to build web and Ajax applications based on their powerful capabilities. While there are many quick application development tools available, Ruby O-N rails seems to have the ability to simplify building AJAX applications.


<title> Create an available Xmlhttpreuqest object </title>
<body>
<div id= "str" ></div><!--requested data will be displayed in the div-->
<input type= "button" value= " Display data "onclick=" post () "/>
<script type=" text/javascript ">
function Ajax_xmlhttp () {
// Creating XMLHttpRequest in IE applies to all versions of ie5.0 above
var msxmlhttp = new Array ("msxml2.xmlhttp.5.0", "msxml2.xmlhttp.4.0", " msxml2.xmlhttp.3.0 "," Msxml2.xmlhttp "," Microsoft.XMLHTTP ");
for (var i=0; i<msxmlhttp.length; i++) {
Try
{
_xmlhttp=new ActiveXObject (msxmlhttp[i));
}
catch (e)
{
_xmlhttp=null;
}
}//Loop create XMLHTTP based on IE browser. End
///If not IE browser, create XMLHttpRequest
if (!_xmlhttp && typeof XMLHttpRequest!= "undefined")
{
_xmlhttp=new xmlhttprequest ();
}
Return _xmlhttp;
}

Send Request function
Function post () {
var ajax = Ajax_xmlhttp (); Assigns a XMLHttpRequest object to a variable.
Ajax.open ("Post", "Web_ajax.asp Tutorial", true);/Set request mode, request file, asynchronous request
Ajax.onreadystatechange = function () {//You can also specify an already-written name
if (ajax.readystate==4) {//data returned successfully
if (ajax.status==200) {//http Request status code returns OK
var xmldata = Ajax.responsexml;
var msg = xmldata.getelementsbytagname ("msg");//Get all MSG elements
var data = Msg[0].firstchild.nodevalue;
document.getElementById ("str"). innerHTML = data;
}
}
}
Ajax.send (NULL);
}
</script>
</body>

web.asp file


<%
' Author: Candon
' to reprint please be sure to keep the above information
' Define a variable to save the XML data
Dim xml
XML = ' <?xml version= ' 1.0 ' Encodi ng= ' gb2312 '?><body> '
XML = xml& ' <msg> a simple ASP output XML example, later in our Ajax tutorial instance, we will use this file for data reading operations </msg>
xml=xml& </body>
response.clear
response.contenttype= "Text/xml"
response.charset= "gb2312"
Response.Write XML
Response.End
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.