function check_jobref_availability(){
if ($job_reference_already_exists == 0) {
$output = TRUE;
} else {
$output = FALSE;
}
echo $output;
}
complete function
function check_jobref_availability(){
$output = 1;
$jobrefference = $this->uri->segment(3); //mysql_real_escape_string($_REQUEST['ptitle']);
$strSQL = "SELECT count(*) FROM projects where ptitle = '" . $jobrefference . "' and companyid = 1";
$job_reference_already_exists = get_singlecolumn($strSQL);
//if it is zero means. no refrence was found and it is good to go to add the new job reference.
if ($job_reference_already_exists == 0) {
$output = 1; // NOT FOUND SO GO AHED
} else {
$output = 0; // MEANS ALREAYD EXISTS give an alert
}
echo $output;
}
This is my PHP Code (rest of the code actually queries the DB) and returns 0 or 1. Based on which i need to return true or false.
var newjobrefrence = $('#newjobrefrence').val().trim();
$.ajax(
{
type: "POST",
url: "<?php echo base_url(); ?>postproject/check_jobref_availability/" + newjobrefrence,
data: {ptitle: newjobrefrence},
success: function(response){
if (response.d == "false") {
jobrefrencealreadyexists = 1;
alert("Job ref found");
}else{
jobrefrencealreadyexists = 0;
alert("Not found");
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
And this is my jquery/ajax call. I am new to jquery/ajax.
All it needs to do is call check_jobref_availability, and based on the return value do an alert.
I have tried different combinations like returning Jason (I am not 100% sure if was doing that correctly either), or returning "True" or "False" and simple true; and false; but I can not see the response in my jquery..
I have got few hair left on my head as I have been pulling them all weekend on this.
Any help would be much appreciated to save my hair style.