如何在CakePHP 2中的$ .ajax url中添加值

时间:2015-11-25 06:38:48

标签: ajax cakephp-2.0 cakephp-2.3

我试图使用ajax发送请求。我有CartsController和方法添加。请帮忙!

TypeError: undefined is not a function
    at reload (http://localhost:3000/assets/ng-table/ng-table.min.js?body=1:140:160)
    at Object.fn (http://localhost:3000/assets/ng-table/ng-table.min.js?body=1:196:24)
    at Scope.$digest (http://localhost:3000/assets/angular/angular.js?body=1:5226:31)
    at Scope.$apply (http://localhost:3000/assets/angular/angular.js?body=1:5305:28)
    at done (http://localhost:3000/assets/angular/angular.js?body=1:3182:26)
    at completeRequest (http://localhost:3000/assets/angular/angular.js?body=1:3306:9)
    at XMLHttpRequest.xhr.onreadystatechange (http://localhost:3000/assets/angular/angular.js?body=1:3279:13) 

2 个答案:

答案 0 :(得分:0)

如果ajax请求没问题,那么请在CartsController的add方法中使用

你可以得到它
if ($this->request->is('post') || $this->request->is('put')) {
    debug($this->request->data['product_id'])
}

答案 1 :(得分:0)

您应该可以通过

访问您在ajax请求中输入的数据
if( $this->request->is('ajax') ) {
    pr($this->request->data['product_id']);
    // Or try printing the whole $this->request->data if you need other items.
}