Guest User

Untitled

a guest
Aug 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. Send array from jQuery(ajax) to PHP
  2. <input type='text' size='30' class='email' value='testing1@gmail.com' />
  3. <input type='text' size='30' class='email' value='testing2@gmail.com' />
  4. <input type='text' size='30' class='email' value='testing3@gmail.com' />
  5. <input type='text' size='30' class='title' value='testing title' />
  6. <input type='text' size='30' class='message' value='testing message' />
  7.  
  8. <script type="text/javascript">
  9. $(function() {
  10. var title = $('.title').val();
  11. var message = $('.message').val();
  12.  
  13. var dataString = 'title=' + title + '&message=' + message;
  14. $.ajax({
  15. type: "POST",
  16. url: "send.php",
  17. data: dataString,
  18. success:function () {
  19.  
  20.  
  21. }
  22.  
  23. });
  24. });
  25. </script>
  26.  
  27. <?php
  28.  
  29.  
  30. $email = $_POST['email'];
  31. $title = $_POST['title'];
  32. $message = $_POST['message'];
  33.  
  34. foreach($email as $value) {
  35.  
  36. //send email
  37.  
  38. }
  39. ?>
  40.  
  41. <form id="the-form">
  42. <input type='email' size='30' name="email[]" value='testing1@gmail.com' />
  43. <input type='email' size='30' name="email[]" value='testing2@gmail.com' />
  44. <input type='email' size='30' name="email[]" value='testing3@gmail.com' />
  45. <input type='text' size='30' name='title' value='testing title' />
  46. <input type='text' size='30' name='message' value='testing message' />
  47. </form>
  48.  
  49. $.ajax({
  50. type: "POST",
  51. url: "send.php",
  52. data: $("#the-form").serialize(),
  53. success: function() {
  54.  
  55. }
  56. });
  57.  
  58. var data = {
  59. title: $('.title').val(),
  60. message: $('.message').val(),
  61. email: $('.email').map(function(){ return $(this).val(); }).get()
  62. };
  63.  
  64. $.ajax({
  65. type: "POST",
  66. url: "send.php",
  67. data: data,
  68. success:function () {
  69.  
  70. }
  71. });
  72.  
  73. var datastring = $('#yourform').serialize();
Add Comment
Please, Sign In to add comment