I need a sanity check here. I'm posting data through an AJAX call but for some reason it comes through as null.
javascript:
var data = {};
data['pkStudyYears'] = id;
data['years'] = [];
data['years']['pkStudyYears'] = id;
data['years']['fkStudyID'] = $('#fkStudyID').val();
data['action'] = action;
data['years']['intStartYr'] = $('#startYearBox').val();
data['years']['intEndYr'] = $('#endYearBox').val();
console.log(data['years']);
var posturl = '<?php echo site_url('manage/climate_indicators/updateStudyYears');?>'
$.when($.ajax({
type: "POST",
url: posturl,
data: data,
dataType: 'json'
}))
.done(function(result) {
console.log(result.status);
if (result.status === 'failed') {
console.log(result.errors);
}
});
php (updateStudyYears)
$postData = $this->input->post(NULL, true);
$yearArray = $postData['years'];
if(empty($yearArray)) {
echo json_encode(array('status'=>'failed', 'errors'=>'Years are empty'));
exit();
}
I keep getting a failed result with the error "Years are empty". I can't figure out what I'm missing!