简体   繁体   English

简单HTML DOM类的延迟

[英]Delay for Simple HTML DOM Class

I'm using the simple html dom class and have gotten it to work on basic pages and can view the information I want. 我正在使用简单的html dom类,并使它在基本页面上工作,并可以查看我想要的信息。 However, when I attempt to use it on a page that reloads a div with ajax, I can't seem to get it to "wait" before reading the page. 但是,当我尝试在使用ajax重新加载div的页面上使用它时,我似乎无法让它在读取页面之前“等待”。

I basically want it to load the page, then wait 2 seconds before reading the page content (so that the new div has time to load). 我基本上希望它加载页面,然后在读取页面内容之前等待2秒(以便新div有时间加载)。 Is this possible or am I trying to use the class incorrectly? 这是可能的还是我试图错误地使用该类? I'm manually inputting the URL, so it's not a link issue. 我手动输入了URL,所以这不是链接问题。

Example Page : - You can see the load issue when you navigate through the pages. 示例页面 : - 您可以在浏览页面时看到加载问题。

Someone suggested curl and I tried that with the same results. 有人提出卷曲,我尝试了相同的结果。

Thanks in advance. 提前致谢。

如果您只想延迟程序执行一段时间,可以使用Sleep方法( http://php.net/manual/en/function.sleep.php )。

PHP runs on the server. PHP在服务器上运行。 JavaScript (eg AJAX) runs in the browser, after the PHP code on the server has finished producing the page. 在服务器上的PHP代码生成页面之后,JavaScript(例如AJAX)在浏览器中运行。 You can't make a PHP program, running on the server, wait for an event that happens later in the browser. 您无法在服务器上运行PHP程序,等待稍后在浏览器中发生的事件。

You'll need to either load the content for that div using PHP code, or replace the PHP DOM-parsing code with JavaScript code that does the work on the client. 您需要使用PHP代码加载该div的内容,或者使用在客户端上执行工作的JavaScript代码替换PHP DOM解析代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM