コードコピーは次のとおりです。
// JavaScriptオブジェクト:Ajaxオブジェクト
// rexleeによって作成されました
function ajax(url、data){
this.url = url;
this.data = data;
this.browser =(function(){
if(navigator.useragent.indexof( "msie")> 0){
「msie」を返します; // IEブラウザ
}それ以外{
「other」を返します; // other
}})();
};
ajax.prototype = {
get:function(){
var結果;
var xmlhttp;
if(this.browser == 'msie'){
試す{
xmlhttp = new ActiveXObject( 'microsoft.xmlhttp');
} catch(e){
xmlhttp = new ActiveXObject( 'msxml2.xmlhttp');
}
}それ以外{
xmlhttp = new xmlhttprequest();
};
xmlhttp.onreadystatechange = function(){
result = xmlhttp.responsetext; // actureは使用できません
};
xmlhttp.open( 'get'、this.url+'?'+this.data、false); // trueはデータをcraう、なぜですか?
xmlhttp.send(null);
返品結果;
}、
投稿:function(){
var結果;
var xmlhttp;
if(this.browser == 'msie'){
xmlhttp = new ActiveXObject( 'microsoft.xmlhttp');
}それ以外{
xmlhttp = new xmlhttprequest();
};
xmlhttp.onreadystatechange = function(){
result = xmlhttp.responsetext; // actureは使用できません
};
xmlhttp.open( 'post'、this.url、false); // falseに設定する必要があります。
xmlhttp.setRequestheader( "content-type"、 "application/x-www-form-urlencoded"); //投稿で、この文はしなければなりません
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();
};
}