การคัดลอกรหัสมีดังนี้:
// JavaScript Object: Ajax Object
// สร้างโดย rexlee
ฟังก์ชั่น ajax (url, data) {
this.url = url;
this.data = ข้อมูล;
this.browser = (function () {
if (navigator.useragent.indexof ("msie")> 0) {
กลับ "msie"; // ie Browser
}อื่น{
กลับ "อื่น ๆ "; // อื่น ๆ
-
-
ajax.prototype = {
รับ: function () {
ผลลัพธ์ var;
var xmlhttp;
if (this.browser == 'msie') {
พยายาม{
xmlhttp = new ActiveXObject ('microsoft.xmlhttp');
} catch (e) {
xmlhttp = new ActiveXObject ('msxml2.xmlhttp');
-
}อื่น{
xmlhttp = ใหม่ xmlhttprequest ();
-
xmlhttp.onreadystatechange = function () {
result = xmlhttp.responsetext; // การปิดไม่สามารถใช้งานได้
-
xmlhttp.open ('รับ', this.url+'?'+this.data, false); // true ไม่สามารถรวบรวมข้อมูลได้ทำไม?
XMLHTTP.SEND (NULL);
ผลการกลับมา;
-
Post: function () {
ผลลัพธ์ var;
var xmlhttp;
if (this.browser == 'msie') {
xmlhttp = new ActiveXObject ('microsoft.xmlhttp');
}อื่น{
xmlhttp = ใหม่ xmlhttprequest ();
-
xmlhttp.onreadystatechange = function () {
result = xmlhttp.responsetext; // การปิดไม่สามารถใช้งานได้
-
xmlhttp.open ('โพสต์', this.url, false); // มันจะต้องตั้งค่าเป็นเท็จมิฉะนั้น responseetext ไม่สามารถคลาน
xmlhttp.setrequestheader ("เนื้อหาประเภท", "แอปพลิเคชัน/x-www-form-urlencoded"); // ในโพสต์ประโยคนี้ต้อง
xmlhttp.send (this.data);
ผลการกลับมา;
-
-
// var a = ใหม่ ajax ('opp2.js', '');
// Alert ('โดย get // n'+a.get ())
// การแจ้งเตือน ('โดยโพสต์ // n'+a.post ());
-
window.onload = function () {
document.getElementById ("btn"). onclick = function () {
var p = document.getElementById ("t") ค่า;
var a = ใหม่ ajax ("phpoop/getPage.php", "page ="+p);
document.getElementById ("Box"). innerhtml = a.get ();
-
-