在我的ajax函数成功部分,当我提醒数据时,我可以看到数据为two dimensional array
但是当我尝试在视图上显示$jobs
数据时,我没有得到$ jobs数组,为什么会如此,我也尝试发送JSON格式的数组来访问它,但它没有工作。哪里有错误?
将数组设为
Array
(
[0] => Array
(
[id] => 1
[jsp_title] => php developer job
)
[1] => Array
(
[id] => 2
[jsp_title] => java developer job
)
)
控制器
public function processjobsearch()
{ //print_r($_POST);
try {
$valToSearch = isset($_POST['keyword']) ? trim($_POST['keyword']) : NULL;
$datepicker = isset($_POST['datepicker']) ? trim($_POST['datepicker']) : NULL;
$jobdate = strtotime($datepicker);
$nature = isset($_POST['nature']) ? trim($_POST['nature']) : NULL;
$location = isset($_POST['location']) ? trim($_POST['location']) : NULL;
$jobs = $this->_model->getJobSearchData($valToSearch, $nature, $location, $jobdate);
//return json_encode($jobs);
$this->_view->set('jobs', $jobs);
return $this->_view->output();
} catch (Exception $e) {
echo '<h1>Application error:</h1>' . $e->getMessage();
}
}
查看
<script>
function jobsearch()
{
var form=$("#jobSearchForm")
//$("#result").html("<img alt="ajax search" src='ajax-loader.gif'/>");
$.ajax({
type: 'POST',
url: '/jobs/processjobsearch/',
data: form.serialize(),
success: function(data){
//alert(data);
$("#keyword").val("");
}
});
}
</script>
<table border='solid'>
<tr><th>Title</th><th>Description</th></tr>
<?php print_r($jobs); ?>
<?php if ($jobs):
foreach ($jobs as $row => $value): ?>
<tr><td><?php echo $value['jsp_title']; ?></td><td><?php echo $value['jsp_desc']; ?></td></tr>
<?php
endforeach;
else: ?>
<?php endif; ?>
</table>
模型
public function getJobSearchData($valToSearch, $nature, $location, $jobdate)
{
$sql = "SELECT
*
FROM
js_projects
WHERE ";
if($valToSearch || $nature || $location || $jobdate)
{
$sql .= "jsp_title like '%$valToSearch%' OR jsp_nature like '%$nature%' OR jsp_location like '%$location%' OR jsp_date like '%$jobdate%' ";
}
//echo $sql;
$this->_setSql($sql);
$jobs = $this->getAll();
print_r($jobs);
if (empty($jobs))
{
return false;
}
return $jobs;
}