0

I got a question since i'm busy with a shoutbox system. I've added a report input button (it's an image anyway), when you click on it, it have to insert the ID of the message into the database.

However, It's my first time when i create something like this and i would like to stay on the same page (so for example: www.domain.com/shoutbox.php and not www.domain.com/shoutbox.php?p=report) I've read allready that i can use Jquery but i got no idea how to send the ID with it..

You can view the code here: http://pastebin.com/xKP9Aymk I marked the right are with "/// START REPORT AREA" and /// END REPORT AREA"

Can anyone help me with it? Thank you in advance!

megasmurf
  • 17
  • 5
  • If you have no idea how an ajax call works, and you're really so busy, just use a regular link to a script that inserts whatever you like into the DB and just returns a 204 header ? – adeneo Nov 16 '13 at 20:12
  • Welcome to SO! Please consider to add some code to your question (especially what you already tried) and what your _specific_ problem with this code is, as no one here will just do the work for you. At least you may add some pseudo-code, if there simply is no code to show yet, so that we get a general idea of what you want. – KeyNone Nov 16 '13 at 20:13
  • I need the report script for the shoutbox and i would like to stay on the same page. ;-) – megasmurf Nov 16 '13 at 20:14

1 Answers1

0

The easiest way is to put it in a data variable like this:

<div class='shout-btn' data-id='12'>shout</div>

and then something like:

$('.shout-btn').on('click', function(){
   var id=$(this).data('id');
   console.log(id);
   // do the rest here which would be a post; kinda a different question

});

Also check out the answer to this question for intermixing jQuery data functions with html5 data functions; a common source of bugs: Writing to a data-* attribute and getting it with jQuery .data() Prob not relevant to use case here though

Community
  • 1
  • 1
timpone
  • 19,235
  • 36
  • 121
  • 211