【发布时间】:2012-03-08 23:43:17
【问题描述】:
function ajaxFunction(id){
var ajaxRequest;
var response;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
alert("Ajax Failed");
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
response = ajaxRequest.responseText;
}
}
ajaxRequest.open("GET", "http://priest/getpic.php?id="+id, true);
ajaxRequest.send(null);
return response;
}
function lightbox(id) {
var image;
var imageArr;
document.write(image);
image = ajaxFunction(id);
imageArr = image.split('|');
imageSrc = imageArr[0];
imageWidth = imageArr[1];
imageHeight = imageArr[2];
getElementById('lightbox').visibility=visible;
getElementById('lightboximg').src=imageSrc;
if(imageWidth > 700) {getElementById('lightboximg').width=700;}
if(imageHeight > 500) {getElemetnById('lightboximg').height=500;}
}
我遇到的问题是我的代码将 ajaxFunction() 调用到图像变量中,而 ajaxFunction() 没有将任何内容返回到变量中,导致我收到以下错误。
未捕获的类型错误:无法调用未定义的方法“拆分” 灯箱 (匿名函数)
任何帮助将不胜感激。
【问题讨论】:
-
这与“使用正则表达式解析 HTML”的频率相提并论……被stackoverflow.com/questions/9286045/…、stackoverflow.com/questions/562412/… 等欺骗了。跨度>
标签: javascript ajax xmlhttprequest