Jump to content

Recommended Posts

Alright guys, am trying to build a basic PHP commenting system but i would like to add some Jquery/Ajax in the mix so the page doesnt need to reload itself when each comment it posted. Does any one have any simple solutions?

 

this is the project...

http://dvplus.webuda.com/oophptest/database.query.php 

 

I'm doing an extremely similar thing on a side project of mine, but I haven't implemented it yet so I can only say how I'm planning to go about it.

 

Storing all comment divs within a container div, id=container:

1. Use javascript to do very simple checks like to make sure it isn't blank etc.

 

2. If checks are ok, store the required details in javascript variables

 

3. Start an Ajax POST request to send the message and use the GET to send small length details like the name.

 

4. Update the mysql database and if it was successfully updated send back a success message to the javascript, if failed, a failed one.

 

5. If successful, create a div in javascript using

var newdiv = document.createElement('div');

 

6. Set the class/style and any js events to the newdiv and using the details stored earlier set the innerHTML of the newly generated div to be that of the message (and any other details that are needed)

 

7. Using the following, append the container div with the newly created message div

var divToAppend = document.getElementById('container');
divToAppend.appendChild(newdiv);

(I create a var because I intend to append multiple items, if only one is needed you could execute that on one line)

 

8. If it failed on the update just alert them saying so.

 

Hope this helps,

Joe

 

P.s. I like your website design.

Thanks Joe, am going to go through these steps in a short while just going to create the PHP code to update the database first. I was thinking if the comments are loaded dynamically along with the new div, the JavaScript can then display the variables in the mark-up rather than the php but because the php have already stored these variables within the database then if the page was ever to be full reloaded then the php with come into place and display them directly from the database. Is this what you had in mind?

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.