Jquery - $.(post) data response not consistent with PHP
Posted
by
Sasha
on Stack Overflow
See other posts from Stack Overflow
or by Sasha
Published on 2012-10-25T10:39:57Z
Indexed on
2012/10/25
11:00 UTC
Read the original article
Hit count: 122
Jquery code:
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:
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)? What is wrong with this code?
© Stack Overflow or respective owner