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緩存中。 :/ –