Forum Moderators: open
Question: can something be written in javascript and work just as effectively as if it had been written in php? Can both do the same thing, in this case, feed updated, current information to my site whenever the page is visited or refreshed?
Getting this up and running in a timely manner is quite important since January - March is the time in my niche where major announcements are made for new products coming to market.
You'll have to escape single quotes....
JS without being in PHP...
onmouseover="this.className='rolloverh'"
JS now inside of PHP...
onmouseover="this.className=\'rolloverh\'"
So escape single quotes but putting the backslash before it.
Without asking a more specific question though I'm not sure what best example or what suggestions would be better for me to suggest.
This question caught my eye because for the last few days I've been wondering the same thing and trying to figure out the answer. So far I'm concerned about two things:
(1) I'm wondering if there could be a problem with people turning off JS in their browsers, in which case they won't see the dynamic content from Amazon.
(2) I'm wondering if it's possible to write JS code for parsing XML that will run in all browsers. So far I'm getting the impression that it's not.
On the optimistic side of the ledger, I'm also wondering if it's possible to use Amazon's XSLT service to parse the XML, which might knock out concern #2.
Like Shallow I'm very curious to hear more responses about this.
That is the Javascript code is sent as part of the HTML page to the client, then the browser interprets it (or ignores it). The server does not care or interpret the Javascript.
PHP is first interpreted at the server, and most often the PHP interpreter generates an HTML on the fly from the result of the PHP code. That code is sent to the client. The client does not care or see, the PHP code.
The Javascript code CAN do a lot of things PHP cannot, and vice versa. Javascript can validate an input field on a form or take an action on mouse click without talking to the server. This is because all those activites are at the client side, and done by the browser.
PHP can access databases, and manage external files, draw new documents in and create images on the fly for example. But, at the end - when all the stuff is sent to the client, it is only HTML.
Now... you CAN combine the two. You can make a PHP code which generates Javascript dynamically. And, with AJAX a "newer" version of Javascript, you can trigger a piece of PHP on the server, and make it generate a new piece of HTML code.
To answer some of the other questions, yes users can turn off Javascript. Yes, you can parse XML code in Javascript. For IE you would use "XMLHTTP ActiveXObject", for Mozilla/Firefox/Opera/Safari use "XMLHttpRequest".
As a side note -- why does the code require PHP5? I am positive the same tasks can be written/achieved using PHP4. If nothing else, the few portions that would require PHP5 could be rewritten to accomodate PHP4. In all cases -- the code should probably be created to support both, which is not hard to do.