No-refreshing Ajax Url submission page

Source: Internet
Author: User

Especially after the popularity of Jquery, porotype, Ext and other frameworks, a large amount of simplified code can be said to bring the gospel to programmers,
Free from the heavy work of code, you can easily implement the complex functions of writing in the past.
However, there are advantages and disadvantages. Nowadays, programmers who are used to various frameworks and seldom write their own internal source code, there are still a few who remember that Ajax is not actually a complex basic code?
Today, in order not to forget my original enthusiasm, I will post this basic code and review it for myself.

1. For Ajax, judging the browser category is a repetitive and innovative task. This code can be completely encapsulated and called at will.Copy codeThe Code is as follows: function xmlhttp ()
{
Var A = null
Try
{
A = new ActiveXObject ("Msxml2.XMLHTTP ");
}
Catch (e)
{
Try
{
A = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Catch (oc)
{
If (typeof XMLHttpRequest! = "Undefined ")
{
A = new XMLHttpRequest ();
}
}
}
Return;
}

If you don't understand it, it's okay to copy it directly.

2. The next step is to submit the Url code.
The entire process is similar. Most codes can be encapsulated. You only need to pass in the parameters and obtain the results.

Copy codeThe Code is as follows: function Ajax (url)
{
Var XmlHttp = new xmlhttp ();
Try
{
XmlHttp. open ("POST", url, true );
Var result = SendUrl ();
}
Catch (e)
{
Alert (e );
}
}

3.Copy codeThe Code is as follows: function SendUrl ()
{
XmlHttp. send ();
XmlHttp. onreadystatechange = function ()
{
If (XmlHttp. readyState = 4 & XmlHttp. status = 200)
{
Var result = XmlHttp. responseText;
Return result;
}
}
}

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.