Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

78
Views
AJAX query post data coming through empty/NULL

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!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!