나는 다음과 같은 Ajax 호출이 있습니다JQuery와 아약스 성공 함수가 호출되지
$.ajax({
type: 'POST',
url: myBaseUrl + 'Products/addItemToBasket',
dataType: 'json',
data: {
id: window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1),
amount: amount
},
success: function (data) {
alert(data);
var dat = JSON.parse(data);
}
}
});
지금이 PHP에서 다음 메소드를 호출 : 나는 모든 것이 작동을 디버깅 할 때
public function addItemToBasket()
{
if ($this->request->is('post')) {
//todo delete efter at have insat fancybox med valg af antal styk. (sendes via ajax).
$shopping = null;
$item = $this->Product->find('first',array('conditions' => array('Product.id' =>$this->request->data['id'])));
if(isset($_SESSION['basket'])){
$shopping = $_SESSION['basket'];
}else{
$shopping = array();
}
array_push($shopping,$item);
$_SESSION['basket'] = $shopping;
echo json_encode($_SESSION['basket']);
}
}
을 (를 php 함수에 들어간다.) 그리고 내 $_SESSION
변수를 업데이트한다.
그러나 결코 성공 함수를 실행하지 않으며 결코 데이터를 경고하지 않습니다.
내가 뭘 잘못하고 있니?
당신은'json_encode '을 반향 출력해야합니까? . .'? –
this-> request-> is ('post')를 사용하면 cakephp 앱이라고 믿을 수 있습니다. 그렇다면 에코는 출력을 덤프하지 않으므로 연결된 뷰에서 실제로 출력해야합니다. 또한 cakephp와 함께 taggin이 도움이 될 수도 있습니다. – jhnlsn
경고 ("테스트")하거나 중단 점을 설정하면 어떨까요? 성공 함수를 입력하지 않았습니까? –