为什么js的全局变量不起效
varjsonObject=null;functionget_imgcon(){//Ajax+json获取数据库中图片URLvarmyXMLHttpRequest=nul...
var jsonObject=null;
function get_imgcon() { //Ajax+json获取数据库中图片URL
var myXMLHttpRequest = null;
if (window.ActiveXObject) {
myXMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} else {
myXMLHttpRequest = new XMLHttpRequest();
}
var url = "get_img_url.php";
myXMLHttpRequest.open("post", url, true);
myXMLHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
myXMLHttpRequest.onreadystatechange = function(){
if (myXMLHttpRequest.readyState == 4 && myXMLHttpRequest.status == 200) {
var res = myXMLHttpRequest.responseText;
jsonObject = eval(res);
}
};
myXMLHttpRequest.send(null);
}
为什么函数内容部 jsonObject赋值成功,在外却依旧为空? 展开
function get_imgcon() { //Ajax+json获取数据库中图片URL
var myXMLHttpRequest = null;
if (window.ActiveXObject) {
myXMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} else {
myXMLHttpRequest = new XMLHttpRequest();
}
var url = "get_img_url.php";
myXMLHttpRequest.open("post", url, true);
myXMLHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
myXMLHttpRequest.onreadystatechange = function(){
if (myXMLHttpRequest.readyState == 4 && myXMLHttpRequest.status == 200) {
var res = myXMLHttpRequest.responseText;
jsonObject = eval(res);
}
};
myXMLHttpRequest.send(null);
}
为什么函数内容部 jsonObject赋值成功,在外却依旧为空? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询