我已经使用serialize()函数提交了表单输入,并且我已经在php post中获得post所有数据,但是只有多选择下拉post数据获得重复,其他输入数据获得正确格式如下所示:ajax表单提交代码
$("form").submit(function(event){
event.preventDefault();
$.ajax({
cache: false,
url: hiddenUrl + 'home/edit_employee',
data: $( ":input" ).serialize(),
type: "POST",
datatype:"json",
success: function (response) {
// window.location.href = hiddenUrl + "home/listemployee";
}
});
});
并在php端输出中获取post数据,如下所示
<pre>Array
(
[id] => 16
[fname] => abcdestiny
[lname] => patel
[empcode] => 44445
[schoolId] => Array
(
[0] => 2
[1] => 6
[2] => 7
[3] => 2
[4] => 6
[5] => 7
)
[school_id] =>
[tableInc_length] => 50
)
这里学校id是多个选择下拉帖子值,我只选择了3个选项,这些值是2,6,7,但重复的值同时显示在schoolid[]下输出为什么帖子在两次得到相同的值?
您正在传递$(“:input”).serialize()
,因此它只接受输入值,并且下拉列表将位于select标记中。因此,使用$('form').serialize()
或$(this).serialize()
而不是$(“:input”).serialize()