0
我不明白问题所在(我的代码工作,我不知道为什么)。 我的API资源正在工作(因为数据插入数据库中),但我仍然没有找到404方法。Api返回404,但记录插入数据库
这是我的角度控制器
controllers.tradeCtrl = function($scope, $routeParams, userFactory, productsFactory, sessionFactory, $timeout, tradeFactory){
$scope.sendTradeRequest = function() {
var requestedUserId = $scope.user.id_user;
var requestedUserItemsIds = $scope.i;
var myRequestedItemsIds = $scope.o;
tradeFactory.createTrade(requestedUserId, requestedUserItemsIds, myRequestedItemsIds).then(function(response){
console.log(response);
}
我厂
在笨取得app.factory('tradeFactory', ['$http', '$location', function($http, $location){
var factory = {};
factory.createTrade = function(requestedUserId, requestedUserItemsIds, myRequestedItemsIds){
return $http({
method: 'POST',
url: $location.protocol() + '://' + $location.host() + '/server/api/trades/makeTrade',
headers : { 'Content-Type': 'application/x-www-form-urlencoded' },
data : $.param({
requestuserId : requestedUserId,
requestedUserItemsIds : requestedUserItemsIds,
myRequestedItemsIds : myRequestedItemsIds
})
}).then(function successCallback(response){
console.log(response);
return response;
},function errorCallback(response) {
console.log('Failed to create new trade: ' + response);
});
}
return factory;
}]);
我休息控制器
class Trades extends REST_Controller {
public function __construct(){
parent::__construct();
$this->load->model('Model_trades');
}
public function index_get(){
$this->response($this->Model_trades->get_all());
}
public function newTrade_post(){
$otherUserId = $this->input->post('requestuserId');
$otherUserItemIds = $this->input->post('requestedUserItemsIds');
$currentUserItemIds = $this->input->post('myRequestedItemsIds');
$this->response($this->Model_trades->create($otherUserId, $otherUserItemIds, $currentUserItemIds));
}
}
在笨我的模型功能插入新记录
function create($otherUserId, $otherUserItemIds, $currentUserItemIds){
$data = array(
'request_id_user' => $this->session->userdata('id_user'),
'request_products' => $currentUserItemIds,
'response_id_user' => $otherUserId,
'response_products' => $otherUserItemIds,
'date_c' => date("Y-m-d H:i:s"),
'id_status' => 1
);
$this->db->insert('trades', $data);
}
最后安慰了把
POST http://myApp.com/server/api/trades/makeTrade 404 (Not Found)(anonymous function) @ angular.js:10765sendReq @ angular.js:10558serverRequest @ angular.js:10268processQueue @ angular.js:14792(anonymous function) @ angular.js:14808Scope.$eval @ angular.js:16052Scope.$digest @ angular.js:15870Scope.$apply @ angular.js:16160(anonymous function) @ angular.js:23618jQuery.event.dispatch @ jquery-2.1.4.js:4435elemData.handle @ jquery-2.1.4.js:4121
factory.js:266 Failed to create new trade: [object Object]
controllers.js:662 undefined
但新的记录在我的数据库中进行。问题是什么?
thx为答案,但这不是案件,因为我已经有其他模式写的方式,我的情况是,他们工作正常。我也尝试过你的解决方案,返回结果和问题依然存在。我正在调查问题 –
问题出在nginx缓存中。 :/ –