发送选择的值数组 [英] Send select's values in array

查看:108
本文介绍了发送选择的值数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的选择列表中的HTML:

 <输入类型=复选框名称=drive_style值= 1检查/> 123 LT; BR />
<输入类型=复选框名称=drive_style值= 2 /> 123 LT; BR />
<输入类型=复选框名称=drive_style值= 3检查/> 123 LT; BR />
<输入类型=复选框名称=drive_style值= 4 /> 123 LT; BR />
<输入类型=复选框名称=drive_style值= 5检查/> 123 LT; BR />
 

我要发送的(1,3,...)中的检查箱的PHP脚本(我使用AJAX使用jQuery)像一个数组。喜欢的东西: drive_style [指数]

  $。员额('post_reply.php',{'drive_style:$('drive_style')},功能(数据){
        警报(数据);
    });
 

在PHP脚本:

 的print_r($ _ POST ['drive_style']);
 

  

[对象的对象]


UPD : 我的新code:

 <输入类型=复选框名称=drive_style []值= 1检查/> 123 LT; BR />
<输入类型=复选框名称=drive_style []值= 2 /> 123 LT; BR />
<输入类型=复选框名称=drive_style []值= 3检查/> 123 LT; BR />
<输入类型=复选框名称=drive_style []值= 4 /> 123 LT; BR />
<输入类型=复选框名称=drive_style []值= 5检查/> 123 LT; BR />

    .post的$('post_reply.php',{'drive_style:$('输入[名称= drive_style]')序列化()},功能(数据){
        警报(数据);
    });
 

这提醒空字符串。

解决方案

  $(函数(){
VAR系列= $('输入[名称= drive_style]')序列化()。
// PHP  - > $('输入[名称= drive_style []')序列化()。
  警报(连续);
});
 

这给你:

  drive_style = 1&安培; drive_style = 3及drive_style = 5
 

但用PHP工作,你还需要有这样的输入名称:

 <输入类型=复选框名称=drive_style []值= 1检查/> 123 LT; BR />
 

注意: drive_style []

这是很明显,你连锁行业:

  drive_style [] = 1&安培; drive_style [] = 3及drive_style [] = 5
 

I have such select list in html:

<input type="checkbox" name="drive_style" value=1 checked />123<br />
<input type="checkbox" name="drive_style" value=2 />123<br />
<input type="checkbox" name="drive_style" value=3 checked /> 123<br />
<input type="checkbox" name="drive_style" value=4 />123<br />
<input type="checkbox" name="drive_style" value=5 checked />123<br />

I have to send values(1, 3, ...) of checked boxes to the php script (I'm using ajax with jquery) like an array. Something like: drive_style[index].

    $.post('post_reply.php', {'drive_style'  : $('drive_style')}, function(data){
        alert(data);
    });

In PHP script:

print_r($_POST['drive_style']);

[object Object]


upd: My new code:

<input type="checkbox" name="drive_style[]" value=1 checked />123<br />
<input type="checkbox" name="drive_style[]" value=2 />123<br />
<input type="checkbox" name="drive_style[]" value=3 checked />123<br />
<input type="checkbox" name="drive_style[]" value=4 />123<br />
<input type="checkbox" name="drive_style[]" value=5 checked />123<br />

    $.post('post_reply.php', {'drive_style':$('input[name=drive_style]').serialize()}, function(data){
        alert(data);
    });

It alerts empty string.

解决方案

​$(function() {
var serial = $('input[name=drive_style]').serialize();
//php -> $('input[name=drive_style[]]').serialize();
  alert( serial );
});​

this give you:

drive_style=1&drive_style=3&drive_style=5

but for work with php you also need to have input name like this:

<input type="checkbox" name="drive_style[]" value=1 checked />123<br />

NOTE: drive_style[]

that obviously giv you:

drive_style[]=1&drive_style[]=3&drive_style[]=5

这篇关于发送选择的值数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆