|
Posted by Randy Webb on 01/24/06 11:59
one man army said the following on 1/22/2006 3:18 PM:
> In article <AuSdnS-Ieqrk-E7enZ2dnUVZ_vydnZ2d@comcast.com>,
> Randy Webb <HikksNotAtHome@aol.com> wrote STUFF
I don't recall writing "STUFF" but if you say so.
>
> The following describes three situations:
> a) a javascript demo and its structure
I gave you a URL to a demo. The only difference in what I pointed you to
and what you are doing is how the .js files get generated. The page I
pointed you to has static .js files but they could just as easily be
dynamically generated .js files that are generated by PHP.
> b) the attempt at using JS/PHP, and what went wrong
<snip>
>
> ========================================================================
> 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, even if it is static .js files. That is the entire concept/idea
behind dynamically loading them. And, it enjoys wider support than
XMLHTTPReqquest does.
> 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.
And did that query return valid JS Code?
> 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.
I showed you how to pass the variable to PHP from JS and then how to
load the file dynamically and execute the JS in it.
> This all worked. But in the next line of Javascript, upon returning
> from the execution of the PHP via document.body.appendChild(
> scriptElement), 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.
That is a timing issue with regards to the time it takes to download the
..js file. That is why I suggested to you to put the function call at the
end of the .js file and execute it from there.
<snip>
> ========================================================================
> C- The Desired Result
>
> I am attempting to dynamically update a page, based on local databases
> in Main. I tried an experiment with XMLHttpRequest() earlier, but found
> I was not able to call outside of my own domain without purchasing an
> digital signature certificate from Verisign or someone. That led me down
> the path of jsHack(), Dynamically Loaded Scripts. Due to the nature of
> my problem, I believe I can preprocess any data I will need and rely on
> local databases. I have put a large amount of effort into the jsHack()
> approach. Since I have all the parts working and am just missing reading
> the result from PHP back into Javascript, it seems like the right idiom
> might finish the puzzle.
Re-read this entire thread with regards to your posts and mine. I don't
want to have to re-post it all but the answer was posted.
> Also, I want to minimize the URL passing. Eventually there will be
> data that the solution requires is not publicly visible and putting that
> into the URL seems sloppy. Primarily though I am looking for the dynamic
> page updates that are the mark of current browser software.
With loading JS Files on the fly, the URL's that you use will never be
seen by the user unless you are using different pages and navigating in
the browser.
> 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.
You have a good design approach, but stick with it. Don't get
discouraged and do a lot of reading :)
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Navigation:
[Reply to this message]
|