dpiw16824 2016-05-26 07:42
浏览 17
已采纳

如何知道将表格数据发布到codeigniter控制器后知道表格值

How to know after post the form data into codeigniter controller to know form values are shown, the data is not showing on the controller

 <script>
                $('#login_form').submit(function (e)
                {
                    e.preventDefault();
                    var uname = $('#uname').val();
                    var upassword = $('#upassword').val();
                    if (uname == "" || upassword == "")
                    {
                        $('#error').show().html('All Fields are required');
                    } 
                    else {
                        $('#error').html("").hide();
                        $.ajax({
                            type: "POST",
                            url: "<?= base_url(); ?>User_controller/success/",
                            data: {uname: uname, upassword: upassword},
                            datatype: 'script'

                        });
                    }
                    }

            </script>
  • 写回答

3条回答 默认 最新

  • dqlhsm9820 2016-05-26 14:09
    关注

    This answer shows how to check that the expected inputs are received. If there is some other kind of check you want to make you'll need to edit your answer and explain.

    Because you set the ajax option dataType: 'script', it is assumed you want to return javascript. (Note: you use datatype where it should be dataType - the option name is case sensitive.) The "script" I show below serves only as a place holder.

    Test for the presence of your inputs using empty(). If a input->post('item') is not found CI v2+ and CI v3+ returns different data types - FALSE (boolean) and NULL respectively. The empty() function will work for both.

    function success()
    {
       $name = $this->input->post('uname');
       $password = $this->input->post('upassword'); 
    
       if( empty($name) || empty($password) )
       {
          echo "var result = 'fail';";
       } 
       else
       {
         echo "your javascript code here";
       }
    

    You might want to trim the fields values either before posting them or within success() just to make sure the user didn't send a string full of space characters.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度