[英]When using ajax POST for form in codeigniter, not passing through data
我正在尝试通过ajax在我的网站上发布数据,但是由于某种原因,它似乎在回显成功消息,但没有获取移动字段数据。 它只是空白。 当我检查萤火虫时,它会给出响应,但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>
$("mobile")
不是适当的选择器,因为您在任何地方都没有该类型的HTML元素。 可能您想使用$("#mobile")
并查看浏览器的“网络”标签,以使下一次更容易找到此错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.