dqmdlo9674 2017-02-17 07:49 采纳率: 100%
浏览 35
已采纳

Resposexml返回null值

I am new to ajax. I wanted to create a simple webpage where it contains a button if clicked returns image dynamically.But the responseXML returns null value. Here is part of javascript code:

function process()
{
    if(xmlhttp.readyState==4 || xmlhttp.readyState==0)
    {
        xmlhttp.open("GET","image.php",true);
        xmlhttp.onreadystatechange = handleserverresponse;
        xmlhttp.send();
    }else{
        setTimeout('process()',1000);
    }
}

function handleserverresponse()
{
    if(xmlhttp.readyState==4){
        if(xmlhttp.status==200){    
            xmlResponse = xmlhttp.responseXML;
            imag = xmlResponse.documentElement.firstChild.data;
            document.getElementById("divimg").innerHTML=imag;
        }
        else{
            alert("something went wrong");
        }
    }

here is php code:

<?php
header('Content-Type:text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>';

echo "<res>";
echo "<img src="a.jpg"/>";
echo "</res>";

?>
  • 写回答

2条回答 默认 最新

  • douhuike3199 2017-02-18 08:16
    关注

    The reason responseXML was null because there is a mistake in PHP file. I guess We cannot send HTML tags when content type is xml. Instead what we can do is echo source of image and modify JavaScript file to take that source and display using img tag.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测