Ajax问题 求解答 困扰很久了
发表在JavaWeb图书答疑 2013-04-08
是否精华
版块置顶:
在Ie8下运行 ,ajax封装代码 与JAVASCRIPT  JAVAWEB书中的封装代码是一样的 但是运行的时候  IE8左下角弹出黄色感叹号网页错误详细信息

用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; QQDownload 733; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648)
时间戳: Mon, 8 Apr 2013 12:17:52 UTC


消息: 对象不支持此属性或方法
行: 13
字符: 2
代码: 0
URI: http://localhost:8080/charitychina/js/Ajax.js

具体代码var net = new Object(); // 定义一个全局的变量

// 编写构造函数

net.AjaxRequest = function(url, onload, onerror, method, params) {
alert(this.onload+"******");
this.req = null;

this.onload = onload;

this.onerror = (onerror) ? onerror : this.defaultError;

this.loadDate(url, method, params);//=initAjax
alert(this.onload+"******");
};

// 编写用于初始化XMLHttpRequest对象并指定处理函数,最后发送HTTP请求的方法 net.AjaxRequest.prototype.loadDate=

net.AjaxRequest.prototype.loadDate=function(url, method, params) {
alert(1);
if (!method) {

method = "GET"; // 设置默认的请求方式为GET

}

if (window.XMLHttpRequest) { // 非IE浏览器

this.req = new XMLHttpRequest(); // 创建XMLHttpRequest对象

} else if (window.ActiveXObject) { // IE浏览器

// IE浏览器

try {

this.req = new ActiveXObject("Microsoft.XMLHTTP"); // 创建XMLHttpRequest对象

} catch (e) {

try {

this.req = new ActiveXObject("Msxml2.XMLHTTP"); // 创建XMLHttpRequest对象

} catch (e) {
}

}

}

if (this.req) {

try {

var loader = this;

this.req.onreadystatechange = function() {
net.AjaxRequest.onReadyState.call(loader);

};

this.req.open(method, url, true); // 建立对服务器的调用

if (method == "POST") { // 如果提交方式为POST

this.req.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded"); // 设置请求的内容类型

this.req.setRequestHeader("x-requested-with", "ajax"); // 设置请求的发出者

}

this.req.send(params); // 发送请求

} catch (err) {

this.onerror.call(this); // 调用错误处理函数

}

}

};
// 重构回调函数

net.AjaxRequest.onReadyState = function() {
var req = this.req;
alert(net.AjaxRequest.prototype.onload+"++++");
var onload =net.AjaxRequest.prototype.onload;
var onerror=net.AjaxRequest.prototype.onerror;
var ready = req.readyState; // 获取请求状态

if (ready == 4) { // 请求完成

if (req.status == 200) { // 请求成功

onload.call(this);

} else {

onerror.call(this); // 调用错误处理函数

}

}

};

// 重构默认的错误处理函
分享到:
精彩评论 1
无语_mrkj
学分:3155 LV11
2013-04-17
沙发
请问您这是哪本书中的代码?
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照