Jump to content

Working with PHP + Javscript


ueon

Recommended Posts

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?

Link to comment
Share on other sites

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="" />
.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.