Javascript 使用ajax在codeigniter中提交表单
在这里,当我提交表单并检查js文件中的验证时,将调用kickerLogin()函数 获取了Javascript 使用ajax在codeigniter中提交表单,javascript,php,jquery,ajax,codeigniter,Javascript,Php,Jquery,Ajax,Codeigniter,在这里,当我提交表单并检查js文件中的验证时,将调用kickerLogin()函数 获取了datastring的警报消息,然后这不会发送到ajax中提到的我的url,但会提交 function kickerLogin(){ alert('hello friends'); dataString=$('form[name=kickerLog]').serialize(); alert(dataString); $.ajax({ type:"POST",
datastring
的警报消息,然后这不会发送到ajax中提到的我的url,但会提交
function kickerLogin(){
alert('hello friends');
dataString=$('form[name=kickerLog]').serialize();
alert(dataString);
$.ajax({
type:"POST",
url:"<?php echo $GLOBALS['base_url']; ?>ajax/user-ajax.php?mode=kickerLogin",
cache: false,
data: dataString,
dataType: "json",
success: function(data) {
alert(data);
if(data.success == "yes")
{
$('#kickerLog').submit();
}
else if(data.success == "no")
{
if(data.status=="emailfail"){
$('li.log_error').show();
$('li.log_error').html("Email id not verified");
}
else if(data.status=="rejected"){
alert("Your account is inactive by admin");
}
else{
$('li.log_error').show();
$('li.log_error').html("Invalid Email / Password");
$("#loginEmail").css("border","1px solid red");
$("#loginPassword").css("border","1px solid red");
}
}
else {
alert(" Occured internal Error.please check network connection" );
}
}
});
}
函数kickerLogin(){
警惕(“你好朋友”);
dataString=$('form[name=kickerLog]')。序列化();
警报(数据串);
$.ajax({
类型:“POST”,
url:“ajax/user ajax.php?mode=kickerLogin”,
cache:false,
数据:dataString,
数据类型:“json”,
成功:功能(数据){
警报(数据);
如果(data.success==“是”)
{
$(#kickerLog')。提交();
}
else if(data.success==“否”)
{
if(data.status==“emailfail”){
$('li.log_error').show();
$('li.log_error').html(“电子邮件id未验证”);
}
else if(data.status==“已拒绝”){
警报(“管理员未激活您的帐户”);
}
否则{
$('li.log_error').show();
$('li.log_error').html(“无效的电子邮件/密码”);
$(“#loginEmail”).css(“边框”,“1px实心红色”);
$(“#loginPassword”).css(“边框”,“1px实心红色”);
}
}
否则{
警报(“发生内部错误,请检查网络连接”);
}
}
});
}
您不能在js文件中使用
。在你的观点中包括这一点可能会奏效。在视图中使用
而不是
。如果js函数kickerLogin()
位于js文件中,则不能使用“”
调用
kickerLogin()
函数时将url作为一个参数传递建议不要在CI中调用外部文件
//Instead of this
url:"<?php echo $GLOBALS['base_url']; ?>ajax/user-ajax.php?mode=kickerLogin",
//Use this
//Where ajax is a controller ajax.php user_ajax is a function in it.
url:"<?php echo site_url();?>/ajax/user_ajax?mode=kickerLogin",
//ajax.php controller
function user_ajax(){
$data['mode'] = $this->input->get('mode');
//Here load the file
$this->load->view('user-ajax');
}
//而不是这个
url:“ajax/user ajax.php?mode=kickerLogin”,
//用这个
//其中ajax是控制器ajax.php用户_ajax是其中的一个函数。
url:“/ajax/user\u ajax?mode=kickerLogin”,
//php控制器
函数用户_ajax(){
$data['mode']=$this->input->get('mode');
//在这里加载文件
$this->load->view('user-ajax');
}
如何调用kickerLogin()?附加到事件?控制台中有错误吗?直接在浏览器中点击ajax url进行检查,并检查控制器函数是否被调用,控制台中是否有错误?如果是,请粘贴在此处。