RE: [PHP] newbie - function is undefined
[snip] Oh no no no. You can use PHP to GENERATE JS, CSS, HTML, XML, etc. You just can't CALL JS from PHP and get a response.[/snip] Fair enough, I just wanted to make sure that we were all on the same page because some of the answers given to the OP may have been somewhat confusing. Many of you know how much I have tried to make sure that posters in the past have understood the difference between client-side vs. server-side. AJAX blurs that line for some developers but I still believe that line to be steadfastly in place. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newbie - function is undefined
On Mon, Apr 04, 2011 at 08:03:46AM -0500, Jay Blanchard wrote: > [snip] > Short answer : yes. > Medium answer : probably, but really yes. > Long answer : unless you are providing some sort of mechanism to hold > the current state of PHP, eject the required JS code to get a value > from the client and return it to the server which then recreates the > working environment and carries on execution (try debugging THAT), > then almost certainly. > [/snip] > > So dynamically generated pages by PHP shouldn't spit out any JS of any > type? Spit out all the Javascript you want with dynamically generated PHP pages. Just don't try to call a Javascript function from PHP. That was the OP's mistake. Paul -- Paul M. Foster http://noferblatz.com http://quillandmouse.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newbie - function is undefined
On 4 April 2011 14:03, Jay Blanchard wrote: > [snip] > Short answer : yes. > Medium answer : probably, but really yes. > Long answer : unless you are providing some sort of mechanism to hold > the current state of PHP, eject the required JS code to get a value > from the client and return it to the server which then recreates the > working environment and carries on execution (try debugging THAT), > then almost certainly. > [/snip] > > So dynamically generated pages by PHP shouldn't spit out any JS of any > type? > Oh no no no. You can use PHP to GENERATE JS, CSS, HTML, XML, etc. You just can't CALL JS from PHP and get a response. I use PHP to create JS code a LOT. The CSS/JS Combinator uses PHP to shrink and cache the JS and CSS code to reduce the number of hits a page generates. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] newbie - function is undefined
On Mon, 2011-04-04 at 08:03 -0500, Jay Blanchard wrote: > [snip] > Short answer : yes. > Medium answer : probably, but really yes. > Long answer : unless you are providing some sort of mechanism to hold > the current state of PHP, eject the required JS code to get a value > from the client and return it to the server which then recreates the > working environment and carries on execution (try debugging THAT), > then almost certainly. > [/snip] > > So dynamically generated pages by PHP shouldn't spit out any JS of any > type? > That's not what he said. PHP can more than adequately output Javascript (or any other kind of output you can think of really, such as XML, PDF, images, etc), it's just generally most people use it to output HTML. Quite often it's easiest when passing data from PHP to Javascript to do it by outputting Javascript code directly, but it does help to separate PHP from the client-side. So rather than think of embedding PHP in an HTML file, it's really the other way around, because as soon as you take an HTML file and include PHP, the whole thing is parsed by php the program on the server, which then outputs HTML to Apache, rather than Apache just grabbing the plain HTML and sending it to the client. Because web servers (typically) don't parse Javascript code, PHP knows nothing about the functions you've declared in it, even if PHP was responsible for outputting the Javascript code itself, in much the same way that you wouldn't expect PHP to output CSS and know whether your browser has correcly applied the styles or not. Everything that happens on the client-side is outside of PHP and the server. Thanks, Ash http://www.ashleysheridan.co.uk
RE: [PHP] newbie - function is undefined
[snip] Short answer : yes. Medium answer : probably, but really yes. Long answer : unless you are providing some sort of mechanism to hold the current state of PHP, eject the required JS code to get a value from the client and return it to the server which then recreates the working environment and carries on execution (try debugging THAT), then almost certainly. [/snip] So dynamically generated pages by PHP shouldn't spit out any JS of any type? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newbie - function is undefined
On 4 April 2011 12:12, Jay Blanchard wrote: > So all of the pages I generate with PHP that call JavaScript functions > and libraries are doing it wrong? Short answer : yes. Medium answer : probably, but really yes. Long answer : unless you are providing some sort of mechanism to hold the current state of PHP, eject the required JS code to get a value from the client and return it to the server which then recreates the working environment and carries on execution (try debugging THAT), then almost certainly. Under normal circumstances, the PHP code is completely finished running before anything gets to the client. There is no mechanism for allowing _this_ script to get a response to a JS call whilst running. It is like the game of "pass the parcel". Your job (as in the PHP script) is to unwrap 1 layer of paper and pass it on. That's it. PHP runs and builds the appropriate output in response to the request that the server directed to the PHP handler. Once the output has been passed to the server, the PHP script is finished. Whilst building the output, PHP cannot talk to the client. At the most fundamental level, the client (the browser) is not listening for anyone other than a response to the request it made to the server. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] newbie - function is undefined
[snip] JavaScript is a browser-side language, browsers have cache, cache sticks around, meaning that you can tell the browser to cache the JS file and not download it from the server (every time) if its being included on the browser end (which js is). All means faster page load times post initial load, and less bandwidth. If you include the JS file with php, every time you request the page the javascript will be pulled from your hard drive by php and sent back as a part of the server response (your end web page). [/snip] So all of the pages I generate with PHP that call JavaScript functions and libraries are doing it wrong? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newbie - function is undefined
On Friday, 1 April 2011 at 22:43, Alex Nikitin wrote: JavaScript is a browser-side language, browsers have cache, cache sticks > around, meaning that you can tell the browser to cache the JS file and not > download it from the server (every time) if its being included on the > browser end (which js is). All means faster page load times post initial > load, and less bandwidth. If you include the JS file with php, every time > you request the page the javascript will be pulled from your hard drive by > php and sent back as a part of the server response (your end web page). I think given the nature and level of the original question, talking about the browser cache is only likely to confuse the poor chap. Jim: Ignore the browser cache for now and focus on learning the difference between javascript and PHP and which one should be used in what situations. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ > On Fri, Apr 1, 2011 at 5:32 PM, Jim Giner wrote: > > > > > function. Try something like: > > ... > > echo 'heaading contains: getText("h2")'; > > ... > > > > I tried it - no better. > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newbie - function is undefined
And the way to do this is? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newbie - function is undefined
JavaScript is a browser-side language, browsers have cache, cache sticks around, meaning that you can tell the browser to cache the JS file and not download it from the server (every time) if its being included on the browser end (which js is). All means faster page load times post initial load, and less bandwidth. If you include the JS file with php, every time you request the page the javascript will be pulled from your hard drive by php and sent back as a part of the server response (your end web page). ~ Alex On Fri, Apr 1, 2011 at 5:32 PM, Jim Giner wrote: > > function. Try something like: > ... > echo 'heaading contains: getText("h2")'; > ... > > I tried it - no better. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] newbie - function is undefined
On Fri, Apr 1, 2011 at 2:32 PM, Jim Giner wrote: > > function. Try something like: > ... > echo 'heaading contains: getText("h2")'; > ... > > I tried it - no better. > Did you still get the "function undefined" error? -- Sláinte, Richard S. Crawford (rich...@underpope.com) http://www.underpope.com Publisher and Editor in Chief, Daikaijuzine (http://www.daikaijuzine.com)
Re: [PHP] newbie - function is undefined
function. Try something like: ... echo 'heaading contains: getText("h2")'; ... I tried it - no better. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newbie - function is undefined
Thanks - now I see. the message means that it can't find a php function called getText. Doh! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newbie - function is undefined
Maybe try: echo 'getText("p1")'; I think that should work. Good luck. Cheers, Micky -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php