在codeigniter中使用ajax POST表单时,不传递数据

时间:2018-01-22 16:01:12

标签: php jquery codeigniter

我试图通过我的网站通过ajax发布数据,但由于某种原因,它似乎回应成功消息,但没有获得移动现场数据。它只是空白。当我用firebug检查时,它会给出响应,但POST选项卡是空的。

我的控制器包含以下内容:

function submit()
 {
     //set validation rule

         // get post data
         $emailid = $this->input->post('mobile');

         // write your database insert code here


         echo "<div class='alert'>Thanks for Subscribing! Please stay tuned to get awesome tips...</div> here is $emailid";

 }

我的观点包含:

<label>Mobile</label>

<input type="number" name="mobile" id="mobile" class=" form-control"  />

<button type ="submit" id="submit" name="submit"  class="btn btn-info btn-block" /> NEXT </button>

JS

                <script type="text/javascript">
                     $("#submit").click(function(e) {
                         e.preventDefault();
                         var mobile = $("mobile").val();
                         $.ajax({
                             url: "https://cheddarplatform.com/complete/submit",
                             method: "POST",
                             data: {mobile: mobile},
                             success: function(data) {
                                 $("#message").html(data);
                             },
                             error: function() {
                                 alert("Please enter valid email id!");
                             }
                         });
                     });
                     </script>

1 个答案:

答案 0 :(得分:1)

$("mobile")不是正确的选择器,因为您在任何地方都没有该类型的HTML元素。您可能希望使用$("#mobile")并查看浏览器的网络标签,以便下次更轻松地找到此错误

相关问题