Home >Backend Development >PHP Tutorial >javascript - 请教个问题,这里的这个1怎么获取呀

javascript - 请教个问题,这里的这个1怎么获取呀

WBOY
WBOYOriginal
2016-06-06 20:11:381128browse

javascript - 请教个问题,这里的这个1怎么获取呀

<code>            var counter = xmlHttp.responseXML.getElementsByTagName("count")[0].firstChild.data;</code>

回复内容:

javascript - 请教个问题,这里的这个1怎么获取呀

<code>            var counter = xmlHttp.responseXML.getElementsByTagName("count")[0].firstChild.data;</code>

<code>function startCallback(){
                if(xmlHttp.readyState == 4){
                    if(xmlHttp.status == 200){
                        setTimeout("pollServer()",5000);
                        refreshTime();
                    }
                }
            }
            
            function pollServer(){
                var url = "DynamicUpdateServlet.php?task=foo" + counter();
                createXMLHttpRequest();
                xmlHttp.open("GET",url,true);
                xmlHttp.onreadystatechange = pollCallback;
                xmlHttp.send(null);
            }
            
            function counter(){
                var res = "&counter=";
                var count = xmlHttp.responseXML.getElementsByTagName("count")[0].firstChild.data;
                res += count;
                return res;
            }
            
            </code>

pollServer() 中调用counter() 要放到 createXMLHttpRequest();前面

可以通过使用PHP的XMLReader内置类获取

http://www.jb51.net/article/80437.htm

两种方法 一:解析XML 二:正则匹配

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