Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Send array from jQuery(ajax) to PHP
- <input type='text' size='30' class='email' value='testing1@gmail.com' />
- <input type='text' size='30' class='email' value='testing2@gmail.com' />
- <input type='text' size='30' class='email' value='testing3@gmail.com' />
- <input type='text' size='30' class='title' value='testing title' />
- <input type='text' size='30' class='message' value='testing message' />
- <script type="text/javascript">
- $(function() {
- var title = $('.title').val();
- var message = $('.message').val();
- var dataString = 'title=' + title + '&message=' + message;
- $.ajax({
- type: "POST",
- url: "send.php",
- data: dataString,
- success:function () {
- }
- });
- });
- </script>
- <?php
- $email = $_POST['email'];
- $title = $_POST['title'];
- $message = $_POST['message'];
- foreach($email as $value) {
- //send email
- }
- ?>
- <form id="the-form">
- <input type='email' size='30' name="email[]" value='testing1@gmail.com' />
- <input type='email' size='30' name="email[]" value='testing2@gmail.com' />
- <input type='email' size='30' name="email[]" value='testing3@gmail.com' />
- <input type='text' size='30' name='title' value='testing title' />
- <input type='text' size='30' name='message' value='testing message' />
- </form>
- $.ajax({
- type: "POST",
- url: "send.php",
- data: $("#the-form").serialize(),
- success: function() {
- }
- });
- var data = {
- title: $('.title').val(),
- message: $('.message').val(),
- email: $('.email').map(function(){ return $(this).val(); }).get()
- };
- $.ajax({
- type: "POST",
- url: "send.php",
- data: data,
- success:function () {
- }
- });
- var datastring = $('#yourform').serialize();
Add Comment
Please, Sign In to add comment