高人们给看看,为什么这个例子提示xmlHttp未定义

aessjz 2009-03-27 03:36:07
function makeRequest(url, functionName, httpType, sendData) {
xmlHttp = false;
if (!httpType) httpType = "GET";

if (window.XMLHttpRequest) { // Non-IE...
xmlHttp = new XMLHttpRequest();
if (xmlHttp.overrideMimeType) {
xmlHttp.overrideMimeType('text/plain');
}
} else if (window.ActiveXObject) { // IE
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}

if (!xmlHttp) {
alert('Cannot send an XMLHTTP request');
return false;
}

var changefunc="xmlHttp.onreadystatechange = "+functionName;
eval (changefunc);
//xmlHttp.onreadystatechange = alertContents;
xmlHttp.open(httpType, url, true);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.send(sendData);
}
function getComList(classid,id,pagenum){
var url = '/e/ajax/index.php?';
var params ='action=getComList' + '&classid=' + classid + '&id=' + id + '&pagenum=' + pagenum;
url+=params;
var functionName=function (){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
if(xmlHttp.responseText!=0){
$("#commentinfo").html(xmlHttp.responseText);
}
else {
$("#commentinfo").html("");
}
}
}
};
makeRequest(url, functionName, "GET", '');
}

function getComPage(classid,id,pagenum){
var url = '/e/ajax/index.php?';
var params ='action=getComPage' + '&classid=' + classid + '&id=' + id + '&pagenum=' + pagenum;
url+=params;
var functionName=function (classid,id,pagenum){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
if(xmlHttp.responseText!=0){
$(".comnav1").html(xmlHttp.responseText);
getComList(classid,id,pagenum);
}
else {
$(".comnav1").html("");
}
}
else if(xmlHttp.readyState!=4)
{
loadING("#commentinfo");
}
}
};
makeRequest(url, functionName(classid,id,pagenum), "GET", '');
}

其实我修改了makeRequest(url, functionName(classid,id,pagenum), "GET", ''); ,以前是
makeRequest(url, functionName, "GET", '');不带参数的,现在带了参数,该了一下functionName的结构。就出现了这种错误,请问怎么会是,谢谢了
...全文
869 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
haozhongtiger 2009-07-31
  • 打赏
  • 举报
回复
把xmlHttp定义为全局的
linkjr 2009-03-27
  • 打赏
  • 举报
回复
xmlHttp = false; //hmlHttp未定义吧

var xmlHttp;
是不是这样?JF
aessjz 2009-03-27
  • 打赏
  • 举报
回复
明白了,可是应该怎么改
function getComPage(classid,id,pagenum){
var url = '/e/ajax/index.php?';
var params ='action=getComPage' + '&classid=' + classid + '&id=' + id + '&pagenum=' + pagenum;
url+=params;
var functionName=function (classid,id,pagenum){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
if(xmlHttp.responseText!=0){
$(".comnav1").html(xmlHttp.responseText);
getComList(classid,id,pagenum);////
}
else {
$(".comnav1").html("");
}
}
else if(xmlHttp.readyState!=4)
{
loadING("#commentinfo");
}
}
};
makeRequest(url, functionName, "GET", '');
}

我这样写,可是var functionName=function (classid,id,pagenum)中的3个参数并没有顺利地传入function (classid,id,pagenum)这个函数里(注:这里传入参数主要是让getComList(classid,id,pagenum)用的)

当然前提是不改变functionName,他就是一个字符串,

请问该怎么改,谢谢
z109876543210 2009-03-27
  • 打赏
  • 举报
回复
functionName 是字符串啊。类型都没搞对..


我这例子吧。。可以传N个参数到回调。。。
http://hi.baidu.com/lael80/blog/item/94da23c766c12edfd0006072.html

示例:

AJAX发的邮件
http://www.i-ones.cn/detail.php?CateTwoID=60
分享[Longing]发送给朋友

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧