Ajax 板


LINE

总共有三个档案分别为.js,.php,.html,名称皆为 .js档负责html与.php中间传输的过程 .php档负责产生图案 .html负则显示.php档所产生之图案 problem:如果.php档不是产生图案的话,.html档可以正常显示,但若 .php是产生图案的话,则.html会显示乱码。 自己猜想问题应该是出现在.js档下面几行的地方 var response = xmlHttp.responseText; myDiv = document.getElementById("myDivElement"); myDiv.innerHTML = response; 因为我是经由.php产生图,所以xmlHttp.responseText这里所收到的内容 应该是一个图吧@@;接着myDiv.innerHTML应该是指插入HTML语言 但我插入的却不是@@,所以应该是这里的问题。 但对WEB语法不熟@@;请各位大大帮帮忙啊 阿李阿斗 ^^ 以下为程式码 .js var xmlHttp = createXmlHttpRequestObject(); var count=0; //-----creates an XMLHttpRequest instance start---- function createXmlHttpRequestObject() { // will store the reference to the XMLHttpRequest object var xmlHttp; // this should work for all browsers except IE6 and older try { // try to create XMLHttpRequest object xmlHttp = new XMLHttpRequest(); } catch(e) { // assume IE6 or older var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"); for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) { try { xmlHttp = new ActiveXObject(XmlHttpVersions[i]); } catch (e) {} } } if (!xmlHttp) alert("Error creating the XMLHttpRequest object."); else return xmlHttp; } //---------creates an XMLHttpRequest instance end------------------- function process() { //---------------count the GD number start--------------------- if(count==400) count=0; else count=count+1; //----------------count the GD number end---------------------- // -------only continue if xmlHttp isn't void start------------------- if (xmlHttp) { // try to connect to the server try { // initiate server access xmlHttp.open("GET", "proxyping.php?count=" + count, true); xmlHttp.onreadystatechange = handleRequestStateChange; xmlHttp.send(null); setTimeout('process()',100); } // display the error in case of failure catch (e) { alert("Can't connect to server:\n" + e.toString()); } } } //---------only continue if xmlHttp isn't void end-------------------- // -----function called when the state of the HTTP request changes-------- function handleRequestStateChange() { // when readyState is 4, we are ready to read the server response if (xmlHttp.readyState == 4) { // continue only if HTTP status is "OK" if (xmlHttp.status == 200) { try { // do something with the response from the server handleServerResponse(); } catch(e) { // display error message alert("Error reading the response: " + e.toString()); } } else { // display status message alert("There was a problem retrieving the data:\n" + xmlHttp.statusText); } } } // -------------function called when the state of the HTTP request changes---------- // -------------handles the response received from the server------------ function handleServerResponse() { var response = xmlHttp.responseText; myDiv = document.getElementById("myDivElement"); myDiv.innerHTML=response; } // ---------------handles the response received from the server------------------- .html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html> <head> <title>Practical AJAX: Accessing Remote Server through Proxy PHP Script</title> <script type="text/javascript" src="proxyping.js"></script> </head> <body onload="process()"> <div id="myDivElement" /> </body> </html> .php <?php // load the error handling module require_once('error_handler.php'); print $count=$_GET['count']; header("Content-type:image/gif"); //设定header以让浏览器将档案视为图档 $im=ImageCreate(800,300); //产生一个空白图 $red=ImageColorAllocate($im,0,0,255); //第一个ImagecolorAllocate决定背景颜色 $white=ImageColorAllocate($im,255,0,255); $yellow=ImageColorAllocate($im,255,255,255); // Imageline($im,1,255,1,$array_line[0],$yellow); //为一线条影像,im像是 一个容器,Imageline像是内容物;前面四个数字表示 //x,y启始位址与结束位置 $fp=fopen("Menu.txt","r"); $j=0; while($line=fgets($fp,$count)) { $array_line=explode(' ',$line); //using the explode function divide the line from string to arry. for($i=0,$num_count=count($array_line);$i<$num_count;$i++) { Imageline($im,(2+$i*1.5+$j*1.5),275,(2+$i*1.5+$j*1.5),275-$array_line[$i],$yellow); } $j=$j+$i; Imagestring($im,5,$j+50,$j+50,$j,$yellow); } Imagegif($im); //输出图档 ImageDestroy($im); //消毁图片 ?> --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.122.79.88
1F:推 alpe:<img id="xx" src="img"> document[xx].src="new image" 03/20 13:01
※ 编辑: adddream 来自: 140.122.79.88 (03/20 13:28)







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Tech_Job站内搜寻

TOP