doudun2565 2016-07-15 04:35
浏览 64
已采纳

如何在PHP中使用AJAX从一个页面到另一个页面将选择框值作为数组传递?

var message = $("#send_message").val();

    var Teaminput = $("#sms_reminder_team").val();
    for (var i = 0; i <Teaminput.length; i++) 
    {
       var team=Teaminput[i];
    }

    var Memberinput = $("#sms_reminder_members").val();
    for (var i = 0; i <Memberinput.length; i++) 
    {
    var members=Memberinput[i];

  }

Get 2 varaibles as array members and team

var parameter = "message="+message+"&team="+team+"&members="+members;
  $.ajax({
  url: base_url+'ajaxfiles/dir_sendmessage',
  type: 'POST',
  data: parameter,
  success: function(data)
  {
    document.getElementById('check').innerHTML = data; 
  }
  });

How to send both array variables using AJAX from current page to "dir_sendmessage".

  • 写回答

4条回答 默认 最新

  • duanliao2310 2016-07-15 04:45
    关注

    Change the below line

    var parameter = "message="+message+"&team="+team+"&members="+members;
    

    to

    var parameter = "message="+message+"&team="+JSON.stringify(team)+"&members="+JSON.stringify(members); 
    

    Edit: Modify like this too

    var team = [];
    var members = [];
    for (var i = 0; i <Teaminput.length; i++) 
    {
       team=Teaminput[i];
    }
    
    var Memberinput = $("#sms_reminder_members").val();
    for (var i = 0; i <Memberinput.length; i++) 
    {
       members=Memberinput[i];
    }
    

    Note: When you add var in each line in the loop, it will declare a new variable. You have to edit like the above code

    After update the code with the JSON.stringify() function, you will be able to get the value as an array in you PHP code

    Ajax will not directly pass Jquery array to PHP

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何解决蓝牙通话音频突发失真问题
  • ¥15 安装opengauss数据库报错
  • ¥15 【急】在线问答CNC雕刻机的电子电路与编程
  • ¥60 在mc68335芯片上移植ucos ii 的成功工程文件
  • ¥15 笔记本外接显示器正常,但是笔记本屏幕黑屏
  • ¥15 Python pandas
  • ¥15 蓝牙硬件,可以用哪几种方法控制手机点击和滑动
  • ¥15 生物医学数据分析。基础课程就v经常唱课程舅成牛逼
  • ¥15 云环境云开发云函数对接微信商户中的分账功能
  • ¥15 空间转录组CRAD遇到问题