Ajax functions, User Registration _ Detection

Source: Internet
Author: User

var xmlhttp;ajax function, user registration _ Detection

Defining AJAX functions
function Ajax () {

if (window. XMLHttpRequest)
{
XmlHttp = new XMLHttpRequest ();//mozilla browser
}
else if (window. ActiveXObject)
{
Try
{
XmlHttp = new Activex0bject ("Msxml2.xmlhttp");//ie old version
}
catch (E)
{}
Try
{
XmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
}
catch (E)
{}
if (!xmlhttp)
{
Window.alert ("Cannot create XMLHttpRequest object instance");
return false;
}
}
}

Get mode
function Ajaxget (url,allid) {

        Ajax ()//calling Ajax functions

        xmlhttp.onreadystatechange = function () {
         if (xmlhttp.readystate = 4) {
             if (xmlhttp.status = =) {
                 document.getElementById (allid). InnerHTML = Xmlhttp.responsetext;
           } else {
                 document.getElementById (allid). InnerHTML = "request failed!";
           }
       }
       }
        xmlhttp.open (' Get ', url, true);
        xmlhttp.send (null);
}


Post mode with data
function Ajaxpost (url,allid,form_obj) {

Gets all the values in the specified table Single-name
var theform = function () {
var query_string= ';
var and= ';
alert (form_obj.length);
for (i=0;i<form_obj.length; i++)
{
E=form_obj;
if (e.name!= ')
{
if (e.type== ' Select-one ')
{
Element_value=e.options[e.selectedindex].value;
}
else if (e.type== ' checkbox ' | | e.type== ' Radio ')
{
if (E.checked==false)
{
Break
}
Element_value=e.value;
}
Else
{
Element_value=e.value;
}
query_string+=and+e.name+ ' = ' +element_value.replace (/\&/g, "%26");
And= "&"
}
}
return query_string;
}//Get End

var thispost = theform ();//Assign the value of the form to the variable

Ajax ()//Call Ajax function

Xmlhttp.onreadystatechange = function () {
if (xmlhttp.readystate = = 4) {
if (Xmlhttp.status = = 200) {
document.getElementById (allid). InnerHTML = Xmlhttp.responsetext;
} else {
document.getElementById (allid). InnerHTML = "request failed!";
}
}
}
Xmlhttp.open (' POST ', url, true);
Xmlhttp.setrequestheader (' Content-type ', ' application/x-www-form-urlencoded; Charset=utf-8 ');
Xmlhttp.send (thispost)//Send thispost form data
}

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.