Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #14439 > unrolled thread
| Started by | Jason C <jwcarlton@gmail.com> |
|---|---|
| First post | 2012-06-10 21:09 -0700 |
| Last post | 2012-06-11 12:11 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.javascript
XMLHttpRequest, using setTimeout() from within child Jason C <jwcarlton@gmail.com> - 2012-06-10 21:09 -0700
Re: XMLHttpRequest, using setTimeout() from within child "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-06-11 09:42 +0000
Re: XMLHttpRequest, using setTimeout() from within child Stefan Weiss <krewecherl@gmail.com> - 2012-06-11 12:11 +0200
| From | Jason C <jwcarlton@gmail.com> |
|---|---|
| Date | 2012-06-10 21:09 -0700 |
| Subject | XMLHttpRequest, using setTimeout() from within child |
| Message-ID | <e9f70f93-4748-4350-bd32-476963d34320@googlegroups.com> |
I'm using XMLHttpRequest to load and show a simple PHP script.
How can I use setTimeout() from within that PHP script without an onClick event? Or does it have to be triggered from the parent?
I'm trying to run this so that after the script loads, it will "close" (or, set the ID to " ", which looks like it closed) after 5 seconds:
<script type="text/javascript">
setTimeout(function() { document.getElementById('lb').innerHTML = ' ' }, 5000);
</script>
[toc] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2012-06-11 09:42 +0000 |
| Message-ID | <XnsA06F7712648AFeejj99@194.109.133.133> |
| In reply to | #14439 |
On 11 jun 2012, you wrote in comp.lang.javascript:
> I'm using XMLHttpRequest to load and show a simple PHP script.
PHP runs on a server, you cannot show such script,
unles as a textfile.
php is off-topic here.
> How can I use setTimeout() from within that PHP script without an
> onClick event?
Again PHP runs on a server, servers have no onclick events.
you can run Javascript on servers, but not in a PHP-script.
> Or does it have to be triggered from the parent?
What do you mean with "parent" here?
> I'm trying to run this so that after the script loads,
Pphp-scripts do not "load" on the client,
they should be executed on a compatible server.
> it will "close"
> (or, set the ID to " ", which looks like it closed) after 5
> seconds:
The following can only be done in a DOM environment,
meaning in a browser on a client, not in a php-script.
XMLHttpRequest responses cannot "run" this way.
> <script type="text/javascript">
>
> setTimeout(function() { document.getElementById('lb').innerHTML =
> ' ' }, 5000);
>
> </script>
>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Date | 2012-06-11 12:11 +0200 |
| Message-ID | <jr4g80$7k2$1@news.albasani.net> |
| In reply to | #14439 |
On 2012-06-11 06:09, Jason C wrote:
> I'm using XMLHttpRequest to load and show a simple PHP script.
>
> How can I use setTimeout() from within that PHP script without an
> onClick event? Or does it have to be triggered from the parent?
>
> I'm trying to run this so that after the script loads, it will
> "close" (or, set the ID to " ", which looks like it closed)
> after 5 seconds:
...
You're leaving a lot of information out of your question, so I'll have
to guess what you're doing. If my guess is incorrect, please be more
specific.
I'm assuming you're using XHR to insert a piece of HTML into the
document via innerHTML (whether or not the HTML is static or generated
by PHP is irrelevant). This piece of HTML contains a script element, and
you want to know why the setTimeout function in that script doesn't work.
If that's correct, then the answer is that scripts inserted with
innerHTML are never evaluated. So the problem isn't the setTimeout
function, but the way you add the script. I would suggest that you
execute the "setTimeout(...)" statement from the same function which
inserts the returned HTML, i.e. the onreadystatechange callback.
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
myTarget.innerHTML = xhr.responseText;
setTimeout(...); // your code here
}
};
If you're using a library for XHR, they usually have a way to add custom
callbacks for the success/error cases.
Another (less elegant) option would be to scan the inserted HTML for
script elements and manually evaluate them.
- stefan
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web