|
楼主 |
发表于 2016-8-4 17:00:13
|
显示全部楼层
我做了修改,但似乎有问题,整个页面还是依旧刷新, register_tpl 这个 view 中代码如下
HTML复制代码 <form action="" method="post" id="userForm">
<div class="row">
<div class="span4 offset4 well">
<?php if (isset($error) && $error): ?>
<div class="alert alert-warning">
<a class="close" data-dismiss="alert" href="#">× </a>
<?php echo $error_info;?>
</div>
<?php endif; ?>
<div class="form-group">
<input type="text" name="phone" class="form-control innerinputx" placeholder="请输入手机号码">
</div>
<div class="form-group">
<input type="password" name="password" class="form-control innerinputx" placeholder="请输入密码">
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6">
<input type="text" class="form-control innerinputx" name="checkcode" placeholder="请输入验证码">
</div>
<div class="col-sm-6">
<input type="submit" name="submit" value="验证码" class="btn btn-lg btn-default btn-block">
</div>
</div>
</div>
<div class="form-group">
<input type="submit" name="submit" value="注册" class="btn btn-lg btn-success btn-block">
</div>
</div>
</form>
<!-- 这里载入了 jquery->
<script>
function makeAjaxCall(){
$.ajax({
type: "post",
url: "register/register_user",
cache: false,
data: $('#userForm').serialize(),
success: function(json){
try{
console.log("json");
}catch(e) {
console.log("json");
}
},
error: function(){
console.log("error");
}
});
}
</script>
复制代码
在register这个controller中代码如下
PHP复制代码
function index () {
$this->show_view(false);
}
function show_view ( $show_error = false ) {
$data['error'] = $show_error;
$data['error_info'] = "";
$this->load->helper('form');
$this->load->view('register_tpl',$data);
}
function register_user () {
$phone = $this->input->post('phone');
$password = $this->input->post('password');
$checkcode = $this->input->post('checkcode');
if($this->input->post('submit') == "验证码") {
$g = "/^1[34578]\d{9}$/";
if (preg_match($g, $phone)) {
echo json_encode(array( 'status' => 1,
'msg' => '已发送'
));
}
else {
echo json_encode(array( 'status' => 0,
'msg' => '手机号码存在'
));
}
}
else {
echo json_encode(array( 'status' => 2,
'msg' => '出错啦'
));
}
}
复制代码
当点击按钮后,出现的问题是,依旧会刷新跳转页面,请问这个那里错了?
|
|