简体   繁体   English

Ajax HTML FORM 不发送输入

[英]Ajax HTML FORM not sending input

i've got a problem I can't figure out.我有一个我想不通的问题。

I have a page (index.php) that open a form, includes another page with PHP (indexsearch.php) and close the form.我有一个页面(index.php)打开一个表单,包含另一个带有PHP(indexsearch.php)的页面并关闭表单。 This included page is working with a script that display some datas from my website, the data are requested on the page with an AJAX function that is linked to search.php, that is working with a table and checkboxes so we can choose which data to work with.这个包含的页面正在使用一个脚本来显示我网站上的一些数据,在页面上使用链接到 search.php 的 AJAX 函数请求数据,该函数使用表格和复选框,因此我们可以选择要使用的数据与。 See this schema :请参阅此架构:

在此处输入图片说明

Everything is working fine but the checkboxes are not send even when they are checked.一切正常,但即使选中复选框也不会发送。 I did added the name and the value in search.php我确实在 search.php 中添加了名称和值

<td> <input type="checkbox" name="ajout[]" value="<?php echo $result['id']; ?>"/> </td>

I also did not opened another form.我也没有打开另一个表格。 So I guess the problem may come from the fact the AJAX datas work as an independant form that is not included in my page.所以我想这个问题可能来自于 AJAX 数据作为一个独立的形式工作的事实,它没有包含在我的页面中。

Please see the html code :请看html代码:

<body>
<div class="division">
                    <table id="text-p">
                        <tr>
                            <td>
                        <form action="" method="get" enctype="multipart/form-data">
                            <textarea id="text-p1" name="text-p1" maxlength="300" placeholder="Text1"></textarea>
                            </td>
                            <td>
                            <textarea id="text-p2" name="text-p2" maxlength="300" placeholder="Text2"></textarea>
                            </td>
                        </tr>

                        <tr>
                            <td>
                            <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
                            Logo : <input name="logo-p1" type="file" accept="image/*">
                            </td>
                            <td>
                            <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
                            Logo : <input name="logo-p2" type="file" accept="image/*">
                            </td>
                        </tr>

              </table>
                </div>


                <div class="division">

        <div width="100%" style="height: 50px;">
            <input type="text" name="recherche" id="recherche" style="width: 75%; float:left; display: inline-block;" placeholder="Rechercher...">
            <div style="float:right;">
                    <input type="radio" name="onglet" value="val1" id="act" checked="">Activité
                    <input type="radio" name="onglet" value="val2" id="sect">Secteur
                    <input type="radio" name="onglet" value="val3" id="ecr">Ecrans
            </div>
        </div>
        <div width="100%" id="resultats">


                    <input id="ok" type="button" class="pageselector" name="pageselector" value="1" checked=""><table id="resultat1" width="100%" style="text-align: center;" class="resultatshow">
                <tbody><tr>
                        <td>Cat</td>
                                            <td>Text-1</td>
                        <td>Text-2</td>
                        <td>Sélec</td>

                </tr>
                        <tr>

                        <td>Cat1</td>
                                                <td>NULL</td>
                        <td>NULL</td>
                        <td> <input type="checkbox" name="ajout[]" value="1"> </td>
            </tr>

                    <tr>

                        <td>CAT2</td>
                                                <td>EMPTY</td>
                        <td>EMPTY</td>
                        <td> <input type="checkbox" name="ajout[]" value="2"> </td>
            </tr>

</table></div>                      
                    <input type="submit" value="UPDATE">

                </div>


            </body>

How can I fix that ?我该如何解决?

I am not sure but I guess it can be caused by square brackets in the name attribute of your checkboxes.我不确定,但我想这可能是由复选框的name属性中的方括号引起的。 If you have reason to do it, you have to work with it properly.如果你有理由这样做,你必须正确地使用它。 For example, here is the HTML form field:例如,这里是 HTML 表单字段:

<input type='checkbox' name='checkbox[myOption]'>

You have to remember that POST is an array of options.您必须记住POST是一组选项。 So doing like above you have to access it in the right way on the server side:所以像上面那样你必须在服务器端以正确的方式访问它:

$_POST['checkbox']['myOption'];

I don't know if that solves your problem but I hope it helps a little bit我不知道这是否能解决您的问题,但我希望它会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM