使用serialize()表单提交获取重复的帖子数据

时间:2019-09-02 06:51:01

标签: php jquery ajax serialization

我已经使用serialize()函数提交了表单输入 而且我已经将所有数据发布在php 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端获取发布数据 输出如下所示

<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 []输出下方 为什么帖子两次获得相同的值?

1 个答案:

答案 0 :(得分:0)

您正在传递 Topic words cs 2 Topic3 {senator, people, power, home, year, believe, ... -0.175486 1 Topic2 {friend, place, love, play, general, house, ye... -0.318839 0 Topic1 {money, doe, fucking, play, love, people, worl... -1.360688 Traceback (most recent call last): File "LDA_test.py", line 141, in <module> corpus = [dictionary.doc2bow(text)] File "/Users/tcssig/anaconda/lib/python3.5/site-packages/gensim/corpora/dictionary.py", line 250, in doc2bow counter[w if isinstance(w, unicode) else unicode(w, 'utf-8')] += 1 TypeError: coercing to str: need a bytes-like object, list found ,因此它将仅采用输入值,而您的下拉列表应位于select标记中。因此请使用$( ":input" ).serialize()$('form').serialize()代替$(this).serialize()