|
Posted by Jasen Betts on 01/23/06 13:09
On 2006-01-22, one man army <newsAT@screenlightDOT.com> wrote:
> B- What I tried and How it Went Wrong
>
> I found by reading USENET and some web sites that there was a hack
> that allowed a dynamic appending of a script element, which then
> executes. By specifying that script element as Javascript, but calling
> the file xxx.php, an arbitrary amount of JS/PHP can be executed, eg
> Dynamically Loaded Scripts.
yes.
> I created a MySQL database with a table of Zip Codes, and the PHP
> snippet which calls the database and executes a simple query. I used
> phpMyAdmin to load the database and create the query string.
>
> In the Intro page I experimented with onSubmit() and the Action in the
> form. I was having problems, so I added a button which simply called a
> javascript function for testing purposes.
>
> I intended to call PHP to do the query, then read the result back in
> Javascript. Since I could not find a way of passing a PHP var into
> something Javascript can read, I set the content of a hidden field to
> the number of items found, or the error msg on SQL error.
>
> This all worked. But in the next line of Javascript, upon returning
> from the execution of the PHP via document.body.appendChild(
> scriptElement)
this is faulty thinking it is not a procedure call, in javascript you
are downloading a file and appending, it to the document and executing
it.
> , the result of the query was not there yet. Apparently
> there is some kind of event loop or somesuch that queued the execution
> of the PHP. The result was there visibly in the browser window, and on
> inspection with the Firefox DOM inspector.
I'n not sure what you mean by event loop, yes the result it not there
immediately but will arrive soon (depending on network etc...)
AIUI the object has an onload property that can be used to activate code
after it has loaded (and executed) basically this is like any other event
handler....
This means you can't reliably do a synchronous request, your script must run
in two parts, one to request the result and a further part to handle the
result.
there's a different handler if it fails but I forget the name
> This is my first Javascript program so I am more than willing to
> change the design approach as appropriate. I appreciate thoughful
> comments or suggestions, and do appreciate the answers I have read on
> USENET that let me get as far as I have.
basically you need to saw it in half and have one half making requests and
the other half handling the responses.
Bye.
Jasen
[Back to original message]
|