코드 사본은 다음과 같습니다.
// javaScript 객체 : ajax 객체
// RexLee에 의해 생성되었습니다
함수 ajax (url, data) {
this.url = url;
this.data = 데이터;
this.browser = (function () {
if (navigator.useragent.indexof ( "msie")> 0) {
"msie"; // 즉, 브라우저를 반환합니다
}또 다른{
"기타"; // 기타 반환
}}) ();
};
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; // closure는 사용할 수 없습니다
};
xmlhttp.open ( 'get', this.url+'?'+this.data, false); // true data, 왜?
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; // closure는 사용할 수 없습니다
};
xmlhttp.open ( 'post', this.url, false); // false로 설정되어야합니다. 그렇지 않으면 responseetext를 크롤링 할 수 없습니다.
xmlhttp.setRequestheader ( "content-type", "application/x-www-form-urlencoded"); // 게시물 에서이 문장이 있어야합니다
xmlhttp.send (this.data);
반환 결과;
}
};
// var a = new ajax ( 'opp2.js', '');
// alert ( 'get // n'+a.get ())
// alert ( 'post // n'+A.post ());
//////////////////////////////////////////////////////////////////////////////////4 //////////////////////////////////////////////////////////////////////////////////4 //////////////////////////
Window.onload = function () {
document.getElementById ( "btn"). onclick = function () {
var p = document.getElementById ( "t"). 값;
var a = new ajax ( "phpoop/getpage.php", "page ="+p);
document.getElementById ( "box"). innerHtml = a.get ();
};
}