Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send multiple values dynamically with Ajax and jQuery

Tags:

jquery

ajax

php

  • I have an unknown amount of clickable buttons. (generated)
  • Every button is connected to multiple values that should be sent through the Ajax call.

I found this to start with:

$.ajax({
    type: "POST",
    url: "some.php",
    data: parameters,
    success: function(msg){
    alert("nothing");
}
});

data contains parameters as far as I know. My parameters are different depending on what button that is clicked.

My guess is that I could use this somewhere? But what if I need to send 3 values?

<input type="button" id="unique-1"> <!-- With values 'test', 3 and 5 -->
<input type="button" id="unique-2"> <!-- With values 'doh2', 8 and 6 -->

I use PHP if you need that info.

Thanks!

like image 299
Jens Törnell Avatar asked Feb 22 '26 11:02

Jens Törnell


1 Answers

Check out this fiddle. The button will find the form that it needs to submit, serialize the data, and alert that string. You would just need to then use that string as the parameter for the data option of the ajax call.

like image 83
Aaron Hathaway Avatar answered Feb 24 '26 01:02

Aaron Hathaway



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!