Home > Web Front-end > JS Tutorial > Share examples of implementing ajax encapsulation by yourself_javascript skills

Share examples of implementing ajax encapsulation by yourself_javascript skills

WBOY
Release: 2016-05-16 16:53:53
Original
1061 people have browsed it

Copy code The code is as follows:

//javascript Object: ajax Object
// Created By RexLee
function Ajax(url,data){
this.url=url;
this.data=data;
this.browser=(function(){
if(navigator .userAgent.indexOf("MSIE")>0) {
                                                                                                                    ();
};
Ajax.prototype={
get:function(){
var result;
var xmlhttp;
if(this.browser=='MSIE' ){
try{
xmlhttp=new ActiveXObject('microsoft.xmlhttp');
}catch(e){
xmlhttp=new ActiveXObject ('msxml2.xmlhttp');
                                      
                                                                                                           = xmlhttp.responseText;//Closure, this cannot be used. Attributes
};
xmlhttp.open('GET',this.url '?' this.data,false);//true cannot fetch data, why?

return result;
},
post:function(){
var result;
var xmlhttp;
if(this.browser=='MSIE'){
xmlhttp=new ActiveXObject ('microsoft.xmlhttp'); {
result = xmlhttp .responseText;//Closure, cannot use this. attribute
       }; > xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");//In POST, this sentence must be
xmlhttp.send(this.data);
}
};

//var a=new ajax('opp2.js','');
//alert('by GET\n' a.get( ))
//alert('by POST\n' a.post());
////////////////////////// //////



window.onload=function(){
document.getElementById("btn").onclick=function(){
var p= document.getElementById("t").value;
var a=new Ajax("phpOOP/getPage.php","page=" p);
document.getElementById("box").innerHTML=a .get();
};
}


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template