|
本帖最后由 NingerJohn 于 2014-10-21 08:16 编辑
CI框架中,使用JQ的ajax时,每次后台都能接收数据,但执行的函数却是error函数。控制器PHP能接收到数据并传到数据库中,但是ajax执行的是error函数1. ajax代码如下
var email = $('input.email').val();
var password = $('input.password').val();
$.ajax({
type:"POST",
url:"register/submit/",
dataType:"json",
data:{"email":email,"password":password},
success:function(){
alert('Success');
return true;
},
error:function(){
alert('Failed');
return false;
}
});
2. PHP控制器代码如下(控制器和数据库模型暂时没有分开)
function submit(){
$this->load->library('input');
$email = $this->input->post('email');
$password = md5($this->input->post('password'));
$sql = "Insert into user (email,password) VALUES ('{$email}','{$password}')";
$this->db->query($sql);
}
|
|