am not sure what is happenning here or what i am doing wrong.
my ajax response from cakephp controller returns null when i do console.log() in chrome developer tool. also when i examine the network tab it says no response. here is my code
view.ctp
var formUrl = "<?php echo Router::url(array('controller' => 'ExamsScores','action' => 'ajaxReturn')); ?>";
//console.log(form);
//console.log(exam);
//console.log(formUrl);
var string = "form="+form + "&exam="+ exam;
$.ajax({
type: "POST",
url: formUrl,
data: string,
dataType: "json",
success: function(response) {
console.log(response);
},
error: function(xhr,status,error) {
console.log(status);
}
});
controller_action
function ajaxReturn(){
if($this->RequestHandler->isAjax()){
$this->autoRender = false;
$form = $this->request->data['form'];
$exam = $this->request->data['exam'];
$results = $this->ExamsScore->query("SELECT concat(students.first_name,' ',students.last_name) as NAME,
exam_type as EXAM,form_name as FORM,sum(score) as TOTAL,avg(score) as MEAN,exams_scores.admission_no from
students,exams,forms,exams_scores where (exams_scores.admission_no = students.admission_no) and
(exams_scores.exam_id = $exam) and (exams.id = $exam) and (students.form_id = $form) and (forms.id = $form)
group by exams_scores.admission_no order by TOTAL desc
");
}
$jsonData = json_encode($results);
//print_r($jsonData);
$this->set('response',$jsonData);
here is the catch..
if i comment out the print_r($jsonData) in the controller..the ajax response is null.. if i dont comment it the response comes back as i expect.
what exactly is causing this to happen and why is the response null because i was only using print_r for debugging purposes.
any help ?