doudun1029 2011-10-30 10:47
浏览 33
已采纳

将数组从jQuery(ajax)发送到PHP

class email is an array of email addresses. How do i get the array in jQuery and then send the data with AJAX to send.php along with class title and message?

    <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>

send.php

<?php


  $email = $_POST['email'];
  $title = $_POST['title'];
  $message = $_POST['message'];

foreach($email as $value) {

//send email

}
?>
  • 写回答

3条回答 默认 最新

  • duanchun5520 2011-10-30 11:07
    关注

    You can do it more simply that Felix King's answer, using serialize(), if you name your inputs:

    <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() {
    
        }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置