MarkHolbrook Posted June 5, 2012 Share Posted June 5, 2012 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! Quote Link to comment Share on other sites More sharing options...
noober Posted June 5, 2012 Share Posted June 5, 2012 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. Quote Link to comment Share on other sites More sharing options...
Ivan Ivković Posted June 6, 2012 Share Posted June 6, 2012 Basically, what he said. Skype me if you need help with syntax n stuff. Quote Link to comment 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.