[英]Jquery - $.(post) data response not consistent with PHP
Jquery code: Jquery代码:
var code = $('#code'),
id = $('input[name=id]').val(),
url = '<?php echo base_url() ?>mali_oglasi/mgl_check_paid';
code.on('focusout', function(){
var code_value = $(this).val();
if(code_value.length != 16 ) {
if ($('p[role=code_msg]').length != 0 ) $('p[role=code_msg]').remove() ;
code.after('<p role=code_msg>Pogrešan kod je unešen.</p>');
} else {
if ($('p[role=code_msg]').length != 0 ) $('p[role=code_msg]').remove() ;
$.post(url, {id : id, code : code_value}, function(data){
if(data != 'TRUE'){
code.after('<p role=code_msg>Uneti kod je neispravan.</p>');
} else {
code.after('<p role=code_msg>Status malog oglasa je promenjen.</p>');
code.after(create_image());
code.remove();
}
});
}
});
PHP (Codeigniter) code: PHP(Codeigniter)代码:
function mgl_check_paid()
{
$code = $this->input->post('code');
$id = $this->input->post('id');
echo ($this->mgl->mgl_check_paid($code, $id)) ? 'TRUE' : 'FALSE';
}
Problem is following: When code is sent and if it is correct, PHP part will echo TRUE , and JS will execute ELSE part (after post), but for some reason it is not doing that (it is executing the first part of the statment)? 问题如下:当发送代码并且它是正确的时,PHP部分将回显TRUE ,并且JS将执行ELSE部分(发布后),但由于某种原因它没有这样做(它正在执行声明的第一部分) )? What is wrong with this code?
这段代码有什么问题?
Make an exit
after echo statement in php code. 在php代码中的echo语句后
exit
。
echo ($this->mgl->mgl_check_paid($code, $id)) ? 'TRUE' : 'FALSE';
exit;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.