ueon Posted June 23, 2011 Share Posted June 23, 2011 I'm trying to work up a commenting system where the moment you enter a comment through a form, it show instantly show up above without the page refreshing. Imagine facebook's commenting system. I know most people would use AJAX for this, but I know its achievable using PHP. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/240227-working-with-php-javscript/ Share on other sites More sharing options...
KevinM1 Posted June 23, 2011 Share Posted June 23, 2011 Without a refresh, your only option is AJAX. Quote Link to comment https://forums.phpfreaks.com/topic/240227-working-with-php-javscript/#findComment-1233948 Share on other sites More sharing options...
EdwinPaul Posted June 23, 2011 Share Posted June 23, 2011 Another option is to use Javascript to set the value of a named formfield in a function...: function setValue(){ . . document.getElementById('formfield').value = your_value; . . } and in your form: . <input type="text" id="firstfield" onchange="setValue()" /> . . <input type="text" id="formfield" value="" /> . Quote Link to comment https://forums.phpfreaks.com/topic/240227-working-with-php-javscript/#findComment-1233960 Share on other sites More sharing options...
KevinM1 Posted June 23, 2011 Share Posted June 23, 2011 Since the comment(s) will likely need to be persisted on the back end, AJAX is the only way to go to emulate a Facebook-like comment system. Quote Link to comment https://forums.phpfreaks.com/topic/240227-working-with-php-javscript/#findComment-1233965 Share on other sites More sharing options...
efficacious Posted June 23, 2011 Share Posted June 23, 2011 or...... you could use javascript to load a hidden Iframe and pass your vars to the iframe behind the scenes via _GET if not sensitive data... or just encrypt it first for what your talking about tho you are probably better off with ajax.. its really not that difficult. if you already know javascript. Quote Link to comment https://forums.phpfreaks.com/topic/240227-working-with-php-javscript/#findComment-1233970 Share on other sites More sharing options...
KevinM1 Posted June 23, 2011 Share Posted June 23, 2011 Remember - GET has a character limit. Not ideal if someone is writing something long. Quote Link to comment https://forums.phpfreaks.com/topic/240227-working-with-php-javscript/#findComment-1233972 Share on other sites More sharing options...
ueon Posted June 23, 2011 Author Share Posted June 23, 2011 I actually know for a fact that facebook uses php for its commenting system =/ so it must mean that javascript is able to integrate with php Quote Link to comment https://forums.phpfreaks.com/topic/240227-working-with-php-javscript/#findComment-1233981 Share on other sites More sharing options...
KevinM1 Posted June 23, 2011 Share Posted June 23, 2011 I actually know for a fact that facebook uses php for its commenting system =/ so it must mean that javascript is able to integrate with php Uh... that's what AJAX is. AJAX is JavaScript which sends requests to the back end. The back end sends a response back to the JavaScript. The JavaScript then inserts the response into the current page in real time. Quote Link to comment https://forums.phpfreaks.com/topic/240227-working-with-php-javscript/#findComment-1233987 Share on other sites More sharing options...
ueon Posted June 23, 2011 Author Share Posted June 23, 2011 I actually know for a fact that facebook uses php for its commenting system =/ so it must mean that javascript is able to integrate with php Uh... that's what AJAX is. AJAX is JavaScript which sends requests to the back end. The back end sends a response back to the JavaScript. The JavaScript then inserts the response into the current page in real time. Yes, i know AJAX is capable of doing what I described. but I'd definitely like to know if anyone here know how to do the same thing with php? Quote Link to comment https://forums.phpfreaks.com/topic/240227-working-with-php-javscript/#findComment-1234052 Share on other sites More sharing options...
Alex Posted June 23, 2011 Share Posted June 23, 2011 I actually know for a fact that facebook uses php for its commenting system =/ so it must mean that javascript is able to integrate with php Uh... that's what AJAX is. AJAX is JavaScript which sends requests to the back end. The back end sends a response back to the JavaScript. The JavaScript then inserts the response into the current page in real time. Yes, i know AJAX is capable of doing what I described. but I'd definitely like to know if anyone here know how to do the same thing with php? AJAX uses PHP (or some other server-side language). I don't think you know what AJAX is. Quote Link to comment https://forums.phpfreaks.com/topic/240227-working-with-php-javscript/#findComment-1234053 Share on other sites More sharing options...
KevinM1 Posted June 23, 2011 Share Posted June 23, 2011 Ultimately, if you want the experience to be seamless, with no page refresh, you'll need to use JavaScript. Why? Because PHP exists only on the server, and has finished executing commands by the time a web page hits your screen. Because of those two things, it can't respond to client side actions. That's why PHP, by itself, always requires a page refresh. Also, try interacting with Facebook with JavaScript turned off. You may be in for a surprise. Quote Link to comment https://forums.phpfreaks.com/topic/240227-working-with-php-javscript/#findComment-1234057 Share on other sites More sharing options...
ueon Posted June 23, 2011 Author Share Posted June 23, 2011 thanks guys, I get it now. I originally thought AJAX was an independent language that will replace php. Guess I was mistaken. Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/240227-working-with-php-javscript/#findComment-1234065 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.