function load_ajax(str)
{
var xmlHttp;
if(window.XMLHttpRequest){
  xmlHttp = new XMLHttpRequest();
} else{
xmlHttp = new ActiveXobject("Microsoft.XMLHTTP");
}   
var url = "control/act_ajax.php?target="+str+"&sid=" + Math.random();
xmlHttp.open("get",url,true);
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=utf-8");
xmlHttp.send(null);
xmlHttp.onreadystatechange =function () {
if (xmlHttp.readyState == 4) {

if (xmlHttp.status == 200) {
var return_str = xmlHttp.responseText;
alert( return_str);
return return_str;


}
}}
function get_blackpic()
{
var bg_img = load_ajax("blackpic");
alert(bg_img);
}
get_blackpic();为什么弹出来 的信息是 undefind

解决方案 »

  1.   

    同顶我也是,这个问题。似乎是open的响应没有成功。楼主知道答案了请告知。谢谢。
      

  2.   

    xmlHttp.responseText;
    =>
    xmlhttp.ResponseText; 试试
      

  3.   

    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=utf-8")这一句去了,这个是post方式提交表单的状态检测那:xmlHttp.status == 200 加一条 || xmlHttp.status == 304
      

  4.   

     xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=utf-8");  //用get请求这句可以不要。另外你php端是怎么写的呢?
      

  5.   

    alert(xmlHttp.ResponseText);
    是可以得到数据的!只是调取函数就得不到数据了,是不是这样传递ajax数据方式不对?