【发布时间】:2013-09-06 11:22:55
【问题描述】:
这可要了我的命。我正在使用 JQuery 1.10.2 和 Cakephp 2.2,我想从 javascript 做一个 GET。这是我的代码:
Javascript:
var arg='/sites/fechas/10-02-2013';
$.get(arg, function(data) {
console.log(":" + data);
});
CakePHP 代码(SitesController.php):
public function fechas($fecha_reserva) {
$this->autoRender = false;
$fechas = $this->Informacion->find('count', array(
'conditions' => array(
'Informacion.fechas' => str_replace('-', '/', $fecha_reserva))
));
return json_encode($fechas);
}
来自 chrome 开发者工具
Request URL:http://my.web.com/sites/fechas/10-02-2013
Request Headers view parsed
GET http://my.web.com/sites/fechas/10-02-2013 HTTP/1.1
Accept: */*
Referer: http://my.web.com/reserva
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36
如果我在浏览器中写入 url,我会得到响应(只是一个数字)。但是从 javascript 我什么也得不到。
【问题讨论】:
-
试试 echo json_encode($fechas);出口;而不是返回
-
@hex4 谢谢。不,它不起作用。
标签: jquery cakephp-2.2