我是一家软件公司的实习生,并且我需要检查为什么假期列表没有打开?我发现问题在于这个php函数但无法在代码中找到错误
public static function API_getYearHolidays($year = false) { //API
if ($year == false) {
$year = date('Y', time());
}
$q = "SELECT * FROM holidays";
$runQuery = self::DBrunQuery($q);
$rows = self::DBfetchRows($runQuery);
$list = array();
if ($year == false) {
$list = $rows;
} else {
foreach ($rows as $pp) {
$h_date = $pp['date'];
$h_year = date('Y', strtotime($h_date));
if ($h_year == $year) {
$list[] = $pp;
}
}
}
if (sizeof($list) > 0) {
foreach ($list as $key => $v) {
$list[$key]['month'] = date('F', strtotime($v['date']));
$list[$key]['dayOfWeek'] = date('l', strtotime($v['date']));
}
}
$r_error = 0;
$return = array();
$return['error'] = $r_error;
$r_data['message'] = "";
$r_data['holidays'] = $list;
$return['data'] = $r_data;
return $return;
}
控制台出错:
requestHolidayList操作中发现了一些错误 TypeError:无法读取未定义的属性“错误” 在holidayList $(http://dev.hr.excellencetechnologies.in/hr/main.aea75426f6f0d3ea338b.js:152712:26) 在tryCatch(http://dev.hr.excellencetechnologies.in/hr/main.aea75426f6f0d3ea338b.js:222594:40) 在Generator.invoke [as _invoke](http://dev.hr.excellencetechnologies.in/hr/main.aea75426f6f0d3ea338b.js:222828:22) 在Generator.prototype。(匿名函数)[as next](http://dev.hr.excellencetechnologies.in/hr/main.aea75426f6f0d3ea338b.js:222646:21) 在下一个(http://dev.hr.excellencetechnologies.in/hr/main.aea75426f6f0d3ea338b.js:121393:27) 在currCb(http://dev.hr.excellencetechnologies.in/hr/main.aea75426f6f0d3ea338b.js:121469:7) 在 holidayList $ @ index.js:17
答案 0 :(得分:0)
更改
返回$ return; 来
如果您在客户端使用JSON.parse(),则返回json_encode($ return); 。
如果直接返回array / NULL并尝试解析它,则会导致JSON.parse()的SyntaxError。