Ajax begins preparation

Time:2021-12-2

Before that, we need to do some simple ajax preparation, but you must have the basic ability to write HTML, JavaScript and DOM. Otherwise, you will have a hard time reading this Ajax tutorial. My purpose is to pass this tutorial. You can use ajax technology to realize, read, add and modify your web pages, Delete data operation. Maybe you are an old bird and despise what I wrote, but I still hope you can see some examples demonstrated in this tutorial. Maybe there will be a place to attract you!
There are two things we need to do below. First, we must create an available XMLHttpRequest object. If you don’t know what XMLHttpRequest is, please read: what is XMLHttpRequest?
Because different browsers have different support standards for XMLHttpRequest objects, the so-called available XMLHttpRequest object means to run the object without errors in ie, FF, chrome and other browsers. We use JavaScript to create the object, And write a function. In future Ajax tutorial examples, we will use this function to call XMLHttpRequest. Look at the following code:

Copy codeThe code is as follows:
<html>
<head>
< title > create an available xmlhttpreuqest object < / Title >
</head>
<body>
<script type=”text/javascript”>
function ajax_xmlhttp(){
//Create XMLHttpRequest in ie, which is applicable to all versions above ie5.0
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;
}
}/ / end of loop creation of xmlhttp. Based on IE browser
//If it is not an IE browser, create an XMLHttpRequest based on a browser such as Firefox
if(!_xmlhttp && typeof XMLHttpRequest != “undefined”)
{
_xmlhttp=new XMLHttpRequest();
}
return _xmlhttp;
}
alert(ajax_xmlhttp());
</script>
</body>
</html>

After running the above code, “object” will pop up in IE browser and “object XMLHttpRequest” will pop up in FF and chrome browsers. If it pops up correctly, it means that the XMLHttpRequest object is created successfully!
Step 2: we use ASP technology to output an XML file. In future Ajax tutorial examples, we will request the file to read, add, delete and modify data. Maybe you don’t know. We can use any language on the server to output the data in XML format. For example, we use ASP to read the data in a table in the database, Then output the data of the table as XML file format to the client. This is also the most standard use method of Ajax! Click View: ASP outputs data in XML format
The following is the source code of the ASP file. You can copy it to your computer for testing


[Ctrl + a] select all notes:To import an external JS, you need to refresh the page again]

Well, the preparation for today’s Ajax system tutorial has been completed. Tomorrow we will have a little trial — reading data in the first trial of Ajax
come from: http://Www.Web666.Net
Author: Kang Dong