我是cakephp的新手。我使用的是cakephp 2.3版。使用ajax自动更新标签时遇到问题,它无法正常工作。
这是我的 CustomersController.php
public $helpers = array('Html', 'Form', 'Js');
public $components = array('Session', 'Paginator', 'RequestHandler');
public function index() {
$this->set('data', 'initial-value');
}
public function updatedata() {
$this->set('data', 'updated-value');
}
这是我的 index.ctp
<h2>Customers</h2>
<div id="latestvalue"><?php echo $data; ?></div>
<script>
$(document).ready(function () {
alert('start');
getvalue();
alert('end');
});
function getvalue() {
$.ajax({
dataType: 'html',
url: "/customers/updatedata",
cache: false,
success: function(data){
$('#latestvalue').html(data);
}
});
}
</script>
显示了“开始”和“结束”提醒窗口,但<div id="latestvalue">
未更新。
任何帮助表示感谢。
答案 0 :(得分:0)
自己找到答案。原因是我需要有updatedata.ctp视图,因为我不需要视图所以我只是将ajax url更改为指向我的json服务,现在它正在运行。