zxb123456 2008-11-06 16:51
浏览 186
已采纳

ajax callback 函数中 写多个document.write()

ajax callback 函数中执行如下js:
document.open("text/html","replace");
document.write("bb");
document.write("cc");
document.close();
浏览器整个是白的;
如果去掉document.open("text/html","replace");
浏览器只显示"bb";
请问这是为什么呢?
怎么才能把bbcc都显示出来呢?

[b]问题补充:[/b]
有两个JSP页面如下
ab.jsp




<br> function aa(jsp){ <br> var xmlreq = false; <br> if (window.XMLHttpRequest) { <br> xmlreq = new XMLHttpRequest(); <br> } else if (window.ActiveXObject) { <br> try { <br> xmlreq = new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;); <br> } catch (e1) { <br> try { <br> xmlreq = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;); <br> } catch (e2) { <br> xmlreq = false; <br> } <br> } <br> }<br> xmlreq.onreadystatechange = getReadyStateHandler(xmlreq, showMs); <br> xmlreq.open(&quot;post&quot;, jsp, true); <br> xmlreq.send(); <br> }<br> function getReadyStateHandler(xmlreq, responseHandler){<br> return function(){ <br> if (xmlreq.readyState == 4) { <br> if (xmlreq.status == 200) {<br> responseHandler(xmlreq);<br> } else {<br><br> alert(&quot;HTTP error &quot; + xmlreq.status + &quot;: &quot; + xmlreq.statusText);<br> }<br> }<br> }<br> }<br> function showMs(xmlreq){<br><br> alert(xmlreq.responseText);<br> document.open(&quot;text/html&quot;,&quot;replace&quot;); <br> document.write(&quot;bb&quot;); <br> document.write(&quot;cc&quot;); <br> document.close(); </p> <pre><code>} &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input type=&quot;button&quot; name=&quot;query1&quot; value=&quot;aa.jsp&quot; onClick=&quot;aa(&#39;aa.jsp&#39;)&quot; /&gt; &lt;input type=&quot;button&quot; name=&quot;query2&quot; value=&quot;ab.jsp&quot; onClick=&quot;aa(&#39;ab.jsp&#39;)&quot; /&gt; &lt;/body&gt; </code></pre> <p></html></p> <p>aa.jsp</p> <p><html><br> <head><br> <title></title><br> </head><br> <body><br> aaaaaa<br> </body><br> </html></p> <p>访问ab.jsp<br> 点击两个按钮就会发现<br> 只有点击第二个按钮才会显示&quot;bbcc&quot;<br> 击第一个按钮浏览器整个是白的。</p> <p>[b]问题补充:[/b]<br> 是会出现我所说的问题吧?<br> 该不会是我浏览器的问题吧!<br> [b]问题补充:[/b]<br> ajax callback 函数中执行如下js:<br> document.open(&quot;text/html&quot;,&quot;replace&quot;);<br> document.write(&quot;bb&quot;);<br> document.write(&quot;cc&quot;);<br> document.close();<br> 浏览器整个是白的;<br> 如果去掉document.open(&quot;text/html&quot;,&quot;replace&quot;);<br> 浏览器只显示&quot;bb&quot;;<br> 请问这是为什么呢?<br> 怎么才能把bbcc都显示出来呢?</p> <p>[b]问题补充:[/b]<br> 有两个JSP页面如下<br> ab.jsp</p> <p><html><br> <head><br> <title></title><br> <script type="text/javascript"><br> function aa(jsp){ <br> var xmlreq = false; <br> if (window.XMLHttpRequest) { <br> xmlreq = new XMLHttpRequest(); <br> } else if (window.ActiveXObject) { <br> try { <br> xmlreq = new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;); <br> } catch (e1) { <br> try { <br> xmlreq = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;); <br> } catch (e2) { <br> xmlreq = false; <br> } <br> } <br> }<br> xmlreq.onreadystatechange = getReadyStateHandler(xmlreq, showMs); <br> xmlreq.open(&quot;post&quot;, jsp, true); <br> xmlreq.send(); <br> }<br> function getReadyStateHandler(xmlreq, responseHandler){<br> return function(){ <br> if (xmlreq.readyState == 4) { <br> if (xmlreq.status == 200) {<br> responseHandler(xmlreq);<br> } else {<br><br> alert(&quot;HTTP error &quot; + xmlreq.status + &quot;: &quot; + xmlreq.statusText);<br> }<br> }<br> }<br> }<br> function showMs(xmlreq){<br><br> alert(xmlreq.responseText);<br> document.open(&quot;text/html&quot;,&quot;replace&quot;); <br> document.write(&quot;bb&quot;); <br> document.write(&quot;cc&quot;); <br> document.close(); </p> <pre><code>} &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input type=&quot;button&quot; name=&quot;query1&quot; value=&quot;aa.jsp&quot; onClick=&quot;aa(&#39;aa.jsp&#39;)&quot; /&gt; &lt;input type=&quot;button&quot; name=&quot;query2&quot; value=&quot;ab.jsp&quot; onClick=&quot;aa(&#39;ab.jsp&#39;)&quot; /&gt; &lt;/body&gt; </code></pre> <p></html></p> <p>aa.jsp</p> <p><html><br> <head><br> <title></title><br> </head><br> <body><br> aaaaaa<br> </body><br> </html></p> <p>访问ab.jsp<br> 点击两个按钮就会发现<br> 只有点击第二个按钮才会显示&quot;bbcc&quot;<br> 击第一个按钮浏览器整个是白的。</p> <p>[b]问题补充:[/b]<br> 是会出现我所说的问题吧?<br> 该不会是我浏览器的问题吧!<br> 我用的是IE6<br> [b]问题补充:[/b]<br> :shock: 没人遇见过这样的问题吗?<br> [b]问题补充:[/b]<br> 改成 xmlreq.open(&quot;post&quot;, jsp, false); <br> 就可以了<br> 不知道异步时出了什么问题?</p>
  • 写回答

1条回答 默认 最新

  • iteye_17163 2008-11-07 10:03
    关注

    不管怎么弄,都没有出现楼主所说的那些问题. :?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧