Jump to content

Accept comments without page reload...


MarkHolbrook

Recommended Posts

Hello everyone!

 

I'm new here.  Looks like a cool resource and I hope I can help out from time to time.

 

I'm a long time embedded systems and device programmer (yes... sigh... 30 years).  I've worked in many languages so picking up new stuff isn't too hard.  As a hobby I create music.  There are a number of "music community" sites around...  www.macjams.com, www.icompositions.com etc.  But for both personal reasons and to learn something new I've been creating my own music community site in PHP with a little JS in a few places.

 

Currently my site uses standard forms (emitted by PHP code) and "submit" requests to gather and validate data from users.  Most of the time this is just fine.  However I have a need for allowing a user to add a comment to a song without reloading the song page as would happen if I did a standard form.

 

The situation is this:  The song page is displayed and there is a JS based HTML5 audio player.  Typically people want to listen to the song and while they are listening they would like to type in a comment like:  Hey... great song!  How did you get that tone on the e-guitar?

 

If I use a standard form and submit the page reloads causing the JS player to stop playing and they have to start listening to the song again.  So I need away to accept some title text and a text area and add it to my SQL database without reloading the page.  I know it is possible of course because it works on other sites but I have no idea how to create this kind of code.

 

I'm assuming it would be JS based and embedded within the HTML as a script I assume.  This is an area I'm notably weak in.  If someone could point me to some examples or suggest a way to proceed I'd be most greatful.    Thanks!

Link to comment
Share on other sites

Have a hidden form field that tells your ajax and SQL which page/id it's on, then you can insert the comment into the database. Each page will get the comments from the database on load, but on success of your ajax, insert the comment into the page by using .append() or whatnot. This will be "faking" the insertion of the comment for the user until it is reloaded.

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.