- 论坛徽章:
- 1
|
现在在jsp1页面用ajax提交一个请求到jsp2,从jsp2返回一个xml到jsp1,
用alert(req.responseText)
弹出窗口显示:
<?xml version="1.0" encoding="UTF-8" ?> <message> <show> <info0>0 </info0> <info1> <![CDATA[ <select name="lb" id="lb1"> <option value="0">父类 </option> <option value="1">新闻 </option> <option value="5">fdfff </option> <option value="4">sdgasg </option> <option value="7">rrrrrrrrrrr </option> </select>]]> </info1> </show> <show> <info0>rrrrrrrrrrr </info0> <info1>rrrrrrrrr </info1> </show> <show> <info0>rr </info0> <info1>0 </info1> </show> <show> <info0>0 </info0> <info1>f </info1> </show> <show> <info0>10 </info0> <info1> </info1> </show> <show> <info0>4 </info0> <info1> <![CDATA[ <select name="pxlb" id="pxlb1"> <option value="1">1 </option> <option value="2">2 </option> <option value="3">3 </option> <option value="4">4 </option> </select>]]> </info1> </show> </message>
但就是不能取得xml中的值
------------------------------------------
alert(req.responseText);
var type=req.responseXML.getElementsByTagName("show");
alert("aa");//到这里执行正常
alert(type[1].childNodes[1].firstChild.data);//这一句不能执行
-------------------------------------------
但如果是从jsp1用ajax提交到servlet的,就能正确得到xml中的值
另外,我发现,用ajax提交到jsp后,再由jsp返回的值总是被添加了很多空白符号,要在req.responseText得到值后再用replace(/^\s*|\s*$/g,"") 才能得到正确的值,但由于返回的是xml,就无法使用替换方法了。 |
|