我是cakephp的新手,試圖實現AJAX
。我有我寫了下面的線圖add.ctp
:cakephp 2.x中的簡單ajax函數不起作用
$('#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);
}
});
}
});
並在OfficenamesController.php
功能get_office_names_by_catagory()
是:
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
@Rikesh仍然是一樣..沒有提醒 – Nitish
它顯示ajax成功請求螢火蟲? –