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 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名