我想在我当前的弹出页面输入otp页面弹出窗口之前检查手机号码是否已注册。
我的控制器
public function VerificationOTP() {
$postData = $this->input->post();
if (isset($postData) && !empty($postData)) {
$this->load->model('DoctorSearch');
$exest = $this->DoctorSearch->checkPhoneNumber($postData,3);
$data['mobileNumber'] = $this->input->post('mobileNumber');
$data['loginOTP'] = ($this->input->post('loginOTP'))?$this->input->post('loginOTP'):'0';
if ($exest['success']) {
$data['mobilePrefix'] = $exest['mobilePrefix'];
$this->session->set_userdata('patmob',$exest['mobileNumber']);
$this->session->set_userdata('patmobp',$exest['mobilePrefix']);
$this->session->set_userdata('paturef',$exest['userRef']);
$this->load->view('pages/otp',$data);
} else {
$msg = '<div class="alert alert-danger">';
$msg .= 'Please Enter Registered Mobile Number';
$msg .= '</div>';
$this->session->set_flashdata("message", $msg);
//$this->session->set_flashdata("message", '');
redirect('verify-mobilenumber');
}
}
}
My script in view page;
$(document).ready(function () {
$("#submit").click(function () {
var mobileNumber = $("#mobileNumber").val();
$("form[name='mobnumber']").validate({
rules: {
mobileNumber: {
required: true
},
},
messages: {
mobileNumber: {
required: "Enter Mobile Number"
},
},
submitHandler: function (form) {
$.ajax({
type: "POST",
url: "<?php echo base_url('verify-mobilenumber'); ?>",
data: {mobileNumber: mobileNumber},
success: function (result) {
if(result){
$("#enter-otp").modal('show');
$("#ver-num").html(mobileNumber);
}
}
});
}
});
});
});
我不想打开#enter-otp popup,直到注册号码为止。我想显示控制器$ msg。='请输入已注册的手机号码';在我当前的弹出窗口中显示失败消息
答案 0 :(得分:0)
您需要在$ .ajax提交中添加dataType,如此
视图文件中的
<div class="modal fade" id="enter-otp" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Error</h4>
</div>
<div id="OptBody" class="text-center">
</div>
</div>
</div>
</div>
<script>
$.ajax({
type: "POST",
url: "<?php echo base_url('verify-mobilenumber'); ?>",
data: {mobileNumber: mobileNumber},
dataType: "json",
success: function (result) {
if(result.errors){
$("#enter-otp").modal('show');
$('#OptBody').append(result.errors);
$("#ver-num").html(mobileNumber);
}
}
});
</script>
在你的控制器文件中,创建一个空数组,它将保存你想要返回的数据并执行json_encode以便能够将其返回。
public function VerificationOTP()
{
$data = array('errors' => NULL);
$postData = $this->input->post();
if (isset($postData) && !empty($postData)) {
$this->load->model('DoctorSearch');
$exest = $this->DoctorSearch->checkPhoneNumber($postData,3);
$data['mobileNumber'] = $this->input->post('mobileNumber');
$data['loginOTP'] = ($this->input->post('loginOTP'))?$this->input->post('loginOTP'):'0';
if ($exest['success']) {
$data['mobilePrefix'] = $exest['mobilePrefix'];
$this->session->set_userdata('patmob',$exest['mobileNumber']);
$this->session->set_userdata('patmobp',$exest['mobilePrefix']);
$this->session->set_userdata('paturef',$exest['userRef']);
$this->load->view('pages/otp',$data);
} else {
$data['errors'] = "<p>Please Enter Registered Mobile Number</p>";
//$this->session->set_flashdata("message", '');
//redirect('verify-mobilenumber');
}
}
echo json_encode($data);
}