我在模态上使用带有CodeIgniter的kyeup函数,但结果未显示。 javaScript 工作第一次警报消息,但 secound 时间返回响应消息未显示。我正在分享代码"HTML ,javaScript,控制器,模型"请分享有价值的想法先生...
.HTML
<input type="text" class="form-control" name="pran_no" id="pran_no" required="">
<div id="msg"> </div>//error mag not show
JavaScript
<script>
$(document).ready(function()
{
$('#pran_no').keyup(function()
{
var pran_no = $('#pran_no').val();
//alert(pran_no);here working fine
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>pran_no_exist",
data: "pran_no="+pran_no,
success: function(response)
{
//alert(response);//here not show error
$('#msg').html(response);
}
});
});
});
</script>
控制器
function pran_no_exist()
{
$result = $this->Cms_model->pran_no_exist();
//echo $result;
}
模型
public function pran_no_exist() {
$pran_no = $this->input->post('pran_no');
$this->db->select('pran_no');
$this->db->from('users');
$this->db->where('pran_no',$pran_no);
$querya = $this->db->get();
if ($querya->num_rows() > 0)
{
echo '<p style="color:red;">Already Existing Pran No.</p>';
}else {
echo '<p style="color:green;">Not Existing Pran No.</p>';
}
}
Javascript
<script>
$(document).ready(function()
{
$('#pran_no').keyup(function()
{
var pran_no = $('#pran_no').val();
//alert(pran_no);here working fine
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>pran_no_exist",
data: {'pran_no':pran_no},
success: function(response)
{
//alert(response);//here not show error
$('#msg').html(response);
}
});
});
});
</script>
控制器
function pran_no_exist() {
$pran_no = $this->input->post('pran_no');
$result = $this->Cms_model->pran_no_exist($pran_no);
if ($result) {
if ($result->num_rows() > 0)
{
echo '<p style="color:red;">Already Existing Pran No.</p>';
}else {
echo '<p style="color:green;">Not Existing Pran No.</p>';
}
}
}
型
public function pran_no_exist($pran_no) {
$this->db->select('pran_no');
$this->db->from('users');
$this->db->where('pran_no',$pran_no);
return $this->db->get();
}
尝试将键更改为输入更改:
Javascript:
<script>
$(document).ready(function()
{
$('#pran_no').keyup(function()
{
var pran_no = $('#pran_no').val();
//alert(pran_no);here working fine
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>pran_no_exist",
data: {pran_no:pran_no},
success: function(response)
{
var result = JSON.parse(response);
if(result == null)
{alert("Not Existing Pran No.");}
else{ alert("alread existing");
}
}
});
});
});
</script>
控制器:
function pran_no_exist() {
$result = $this->Cms_model->pran_no_exist($_POST["pran_no"]);
echo json_encode($result);
}
型号代码:
public function pran_no_exist($pran_no) {
$this->db->select('pran_no');
$this->db->from('users');
$this->db->where('pran_no',$pran_no);
$querya = $this->db->get()->row();
return $querya;
}
$.ajax({
type: 'POST',
url: 'baseurl path',
data: {
'foo': 'bar'
},
success: function(msg){
alert('wow' + msg);
}
});