Home  >  Article  >  Backend Development  >  XMLHttpRequest中responseText如何获取指定<div>的内容,而不是整个HTML的内容

XMLHttpRequest中responseText如何获取指定<div>的内容,而不是整个HTML的内容

WBOY
WBOYOriginal
2016-06-13 13:47:421138browse

XMLHttpRequest中responseText怎么获取指定

的内容,而不是整个HTML的内容
http_request = new XMLHttpRequest;
....
document.getElementById(reobj).innerHTML = http_request.responseText;

现在responseText返回的是整个HTML,怎么才能让其返回我指定标签中的内容?

注: 什么模板,框架都没有用,只是在index.php中加载了一个xmlajax.js文件。上面代码在xmlajax.js中,获取的是index.php的整个HTML代码。如何获取指定标签的内容而不是整个HTML代码!!!




------解决方案--------------------
你不是给自己找麻烦吗?
document.getElementById(reobj).innerHTML = http_request.responseText;
document.getElementById(reobj).innerHTML = document.getElementById(reobj).getElementById('_ajax').innerHTML

------解决方案--------------------
这个的话你怎么不用responseXML啊,让index.php生成一个xml文件,然后用javascrip的DOM读取所需节点的内容!
------解决方案--------------------
index.php

这个请求的文件 你可控么? 如果可控 在里面控制返回的内容就可以了
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn