這裏是我的代碼: 這是一個javascript文件,它從視圖中獲取所選元素,並將該id作爲Ajax請求發送給控制器。Ajax無法檢索數據(CAKEPHP)
function getData (id, e) {
if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
else {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
alert('yes');
}else{
alert('no');
}
}
xmlHttp.open('POST', '/BrandDetail/returnPdetails', true);
xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlHttp.send(id);
e.preventDefault();
}
});
現在這裏的控制器沒有得到請求或響應它。
class BrandDetailController extends AppController {
public $name = 'BrandDetail';
function returnPdetails() {
$id = $_POST['id'];
$data = $this->brandDetail->find('all', array('conditions' => array('brandDetail.id' => $id)));
}
}
1)不包括所有多餘的CSS代碼,2)你的實際問題是什麼3)是否有某種錯誤 - 發生了什麼,什麼是不...等等 – Dave