Ajax no Refresh URL submit page _ajax related

Source: Internet
Author: User
In particular, after the popularity of frameworks such as Jquery,porotype,ext, a lot of simplified code can be said to bring the gospel to programmers,
From the heavy work of the code to release, easy to achieve the past to write complex functions.
But pros and cons, until now, accustomed to using a variety of frameworks, and rarely write their own internal source code of the program staff, there are a few remember Ajax that is not really complicated basic code?
Today, in order not to forget the original enthusiasm, I put the basis of the code and then posted, to their own review.

1. For Ajax, judging a browser's category is a repetitive and uninspired job, and this code can be encapsulated and invoked randomly.
Copy Code code 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 A;
}

Do not explain, anyway, even if you do not understand, directly copied past use is no problem.

2. Next is the code that submits the URL.
The whole process is very much the same, most of the code can actually be encapsulated, as long as the parameters passed in, and then get the results can be.

Copy Code code as follows:

function Ajax (URL)
{
var xmlhttp=new XmlHttp ();
Try
{
Xmlhttp.open ("POST", url,true);
var result=sendurl ();
}
catch (E)
{
Alert (e);
}
}


3.
Copy Code code 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.