【发布时间】:2014-01-30 05:41:43
【问题描述】:
我是 cakephp 新手,正在尝试实现 AJAX 。我有一个视图add.ctp,其中我写了以下几行:
$('#office_type').change(function(){
var office_id = $('#office_type').val();
if(office_id > 0) {
var data = office_id;
var url_to_call = "http://localhost/testpage/officenames/get_office_names_by_catagory/";
$.ajax({
type: "GET",
url: url_to_call,
data = data,
//dataType: "json",
success: function(msg){
alert(msg);
}
});
}
});
而get_office_names_by_catagory()在OfficenamesController.php中的函数是:
public function get_office_name_by_catagory($type = '') {
Configure::write("debug",0);
if(isset($_GET['type']) && trim($_GET['type']) != ''){
$type = $_GET['type'];
$conditions = array("Officename.office_type"=> $type);
$recursive = -1;
$office_names = $this->Officename->find("all",array("conditions"=>$conditions,"recursive"=>$recursive));
}
$this->layout = 'ajax';
//return json_encode($office_names);
return 'Hello !';
}
但不幸的是,它没有提醒任何东西!怎么了 ?
【问题讨论】:
-
不要在函数中只使用
echo "Hello !"。 -
@Rikesh 还是一样..没有警报
-
是否在 firebug 上显示 ajax 成功请求?
-
Get_office_name 或 Get_office_names ?