Codeigniter JQuery ajax发布空值

时间:2016-12-03 07:54:27

标签: javascript jquery ajax codeigniter

我使用jquery ajax将数据发送到控制器,但它返回null。

我只想使用ajax将单个输入文本发送到控制器。



<script>
  $(document).ready(function() {
    $("#sendOtp").click(function(e){
      console.log("working");
      e.preventDefault();
      //var mobileno = $("#mobileno").val();
      $.ajax({
        type:"POST",
        url:"<?php echo base_url()?>"+"index.php/welcome/generateOtp",
        data:  {mobileno: $("#mobileno").val()},
        dataType: "json",
        cache:false,
        success:function(response){
          console.log(response);
        },
        error: function ($data) {
          console.log(data);
        }
      });
    });
  });
</script>
&#13;
&#13;
&#13;

public function generateOtp(){

    $mobile = $this->input->post('mobileno');


    echo $mobile;

}

这是我必须发送数据的html

  <div class="form-group">
                <div class="col-sm-12">
                  <input type="text" class="form-control" name="mobileNo" id="mobileNo" placeholder="mobile">
        <br>
        <button class="btn" id="sendOtp">Send OTP</button>
                </div>
              </div>

0 个答案:

没有答案
相关问题