如何使用名称将选择选项值发布到jQuery ajax中

时间:2018-08-24 15:15:43

标签: php jquery html ajax

我想使用ajax发送节选项值,但仅发送选择 和复选框 问题是该部分和复选框后未定义 thanx高级

php代码

<?php

    $paramateres = new ParametresApp();
    $paramateres->getparametres();
    $max_pages_nbr = $paramateres->max_pages_nbr;
    $idle_deconnexion = $paramateres->idle_deconnexion;
    $show_chat = $paramateres->show_chat;

?>

html代码

    <form id="formparametres" class="form-row row shadow bg-white border row p-5 "
              method="post">

          <div class="form-check col-3 col-lg-3 ">

                <input name="show_chat" id="show_chat" type="checkbox"
                       class="form-check-input" value="<?php echo $show_chat; ?>"
                    <?php if ($show_chat == 1) {
                        echo 'checked="true" ';
                    }
                    ?>

                <label class="form-check-label"
                         for="show_chat"> Autoriser messenger </label>
                </div>
        <div class="col-3 col-lg-3">
                          <label class="form-control-label">idle deconexion</label>
                          <input name="idle_deconnexion" class="form-control"
                                 value="<?php echo $idle_deconnexion; ?>" required>
                    </div>

         <div class="input-wrapper col-4 col-lg-4">
                    <label class="form-control-label">max_pages_nbr</label>
                    <select name="max_pages_nbr" class="form-control" required>
                      <?php  echo '<option value="'.$max_pages_nbr.'">'.$max_pages_nbr.'</option>
                          <option value="5">5</option>
                          <option value="10">10</option>
                          <option value="15">15</option>
                          <option value="20">20</option>
                          <option value="25">25</option>';?>
                    </select>
              </div>
        </form>

jquery代码

      $("form").submit(function (event) {
                    event.preventDefault();
                    var formData =
                     'show_chat=' + $('input[name=show_chat]').val() +                    
                        '&idle_deconnexion=' + $('input[name=idle_deconnexion]').val() +

                        '&max_pages_nbr=' + $('section[name=max_pages_nbr]').val() ;
                    $.ajax({
                        url: "src/admins/inc/save_parametres.inc.php",
                        method: "POST",
                        data: formData, // serializes the form's elements.
                        cache: false,
                        success: function (data) {
                            alert(data);
                        }

                    });

2 个答案:

答案 0 :(得分:0)

尝试

import pyspark.sql.functions as f

df1.alias('a').join(
    df2.alias('b'), ['id_no', 'start_date'], how='outer'
).select('id_no', 'start_date', 
    f.coalesce('b.amount', 'a.amount').alias('amount'), 
    f.coalesce('b.days', 'a.days').alias('days')
).show()

+-----+----------+------+----+
|id_no|start_date|amount|days|
+-----+----------+------+----+
|    1|2016-01-06|  3456|  20|
|    2|2016-01-20|  2345|  19|
|    1|2016-01-03|  4456|  22|
|    3|2016-02-02|  1345|  19|
|    2|2016-01-15|  1234|  45|
|    1|2016-01-01|  8650|  52|
|    2|2016-01-02|  7130|  65|
+-----+----------+------+----+

希望这会对您有所帮助。

答案 1 :(得分:0)

我对所有人都有求解能力

jquery

    $(document).ready(function () {
    $(':checkbox').change(function () {
                if ($(this).attr("value") == 1) {
                    $(this).attr("value", 0)
                } else {
                    $(this).attr("value", 1)
                }
            });
            $("form").submit(function (event) {
                event.preventDefault();
                var formData =

                    'show_chat=' + $('#show_chat').attr("value") +
                    '&idle_deconnexion=' + $('input[name=idle_deconnexion]').val() +
                    '&max_pages_nbr=' + $('#max_pages_nbr option:selected').text() ;

                $.ajax({
                    url: "src/admins/inc/save_parametres.inc.php",
                    method: "POST",
                    data: formData, // serializes the form's elements.
                    cache: false,
                    success: function (data) {
                        alert(data);
                    }

                });
});
});

可能会在页面src / admins / inc / save_parametres.inc.php

<?php
if (isset($_POST)){
    $show_chat= $_POST['show_chat'];
    $idle_deconnexion= $_POST['idle_deconnexion'];
    $max_pages_nbr= $_POST['max_pages_nbr'];


 $sql = "   update dms_parametres set parm_value=".$show_chat ." where  parm_name='show_chat';
            update dms_parametres set parm_value='" . $idle_deconnexion . "' where  parm_name='idle_deconnexion';
            update dms_parametres set parm_value='" . $max_pages_nbr . "' where  parm_name='max_pages_nbr';

    ";

    if (!$parametres->connect()->multi_query($sql)) {
        echo $parametres->connect()->error;
    } else {
        echo 'sucsess';

    }
}
?>