PHP Ajax Learning

Source: Internet
Author: User

Recently reading ajax
You need something that is relatively basic. For more information, see

<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<Meta name = "Generator" CONTENT = "EditPlus">
<Meta name = "Author" CONTENT = "">
<Meta name = "Keywords" CONTENT = "">
<Meta name = "Description" CONTENT = "">
<Script language = "javascript">

If (window. ActiveXObject) // if window declares a function
{
Function XMLHttpRequest () // does not need to be declared in firefox
{
Try {
// Return the object handle
Return new ActiveXObject ("MSXML2.XMLHTTP ");
Return new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (err ){
Alert ("XMLHttpRequest error ");
}
}
}
// Declare an ajax function. This is the ajax entry.
Function ajax (reqtype, url, asynch, respHandle)
{
$ Ajax = new XMLHttpRequest (); // a new xmlhttp pays attention to this function. Do you want to include var to indicate global variables?
If ($ ajax) // check whether new is successful
{
// View the type of submission
If (reqtype. toLowerCase ()! = 'Post '){
InitReq (reqtype, url, asynch, respHandle); // call an initialization Function
} Else
{
Var args = arguments [4]; // if it is post, a parameter should be required.
If (args! = Null & args. length> 0)
{
InitReq (reqtype, url, asynch, respHandle, args); // call an initialization Function
}
}
} Else
{
Alert ('ajax new error ');
}
}
Function initReq (reqType, url, bool, respHandle ){
Try {
$ Ajax. onreadystatechange = respHandle; // you can specify a variable if the function is successfully called.
$ Ajax. open (reqType, url, bool); // open address
If (reqType. toLowerCase () = "post") {// if it is post, it must be of the sending type.
$ Ajax. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded; charset = UTF-8 ");

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.