简体   繁体   English

Ajax更新和表单输入选择字段

[英]Ajax update & form input select field

I have the follow ajax code (using jquery and x-editable plugin) for updating a select field. 我有以下ajax代码(使用jquery和x-editable插件)用于更新选择字段。

            <a href="#" id="days" data-pk="<?php echo $id; ?>" data-url="post.php" data-title="days" data-type="select" class="editable editable-click">
            <?php
                if (!empty($days)) { echo $days;
                } else { echo "Please Select";
                }
                ?>
            </a>
            <script>
                $(function() {
                    $('#days').editable({
                        source : [{
                            value : '',
                            text : 'Please select'
                        }, {
                            value : '1',
                            text : '1 day'
                        }, {
                            value : '30',
                            text : '1 month'
                        }, {
                            value : '360',
                            text : '1 year'
                        }]
                    });
                });
            </script>

After field is updated, it displays the select text '1 day', '1 month' or '1 year' as the way I want. 字段更新后,它将以我想要的方式显示选择的文本“ 1天”,“ 1个月”或“ 1年”。

But after a page refresh, it displays the select value, as '1', '30' or '360'. 但是在刷新页面后,它会显示选择值,如“ 1”,“ 30”或“ 360”。

What I need to do display the text from select? 我需要显示select中的文本吗?

Thank you!!! 谢谢!!!

To remember and display the option user selects you need to store it in session variable in ajax call. 要记住并显示用户选择的选项,您需要将其存储在ajax调用的会话变量中。

Sample high level example: 样本高级示例:

$.ajax{(
  url:../store.php,
  data: optionselected:selected,
  method:post
});

In store.php set it to a session variable and use this for display while user reloads page. store.php将其设置为会话变量,并在用户重新加载页面时使用该变量进行显示。

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

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