API 返回 404,但记录插入到数据库中
Api returns 404, but record is inserted in database
我不明白问题是什么(我的代码正在工作,我不知道为什么)。我的 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
但是我的数据库中有新的记录。问题出在哪里?
您的模型函数不返回任何内容$this->response
因此不会看到真实的返回
尝试
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
);
return $this->db->insert('trades', $data);
}
整个问题出在nginx上。缓存未正确刷新网页。清除缓存后,应用程序将按预期工作。
相关文章:
- 使用formData使用ajax将图像插入数据库
- 如何访问日期并将其插入数据库?节点.JS&MongoDB
- 使用Mysqli、PHP和AJAX的聊天系统正在将空白消息插入数据库
- AJAX PHP 连接将行插入数据库
- 使用 pur Html 和 Javascript 将文件插入数据库
- 将表单数据插入数据库后无法重定向到 html 页面
- 将整数变量插入数据库
- 单击按钮可多次动态添加选择框、文本框和日期,并将这些值插入数据库
- 动态选择列表AJAX和插入数据库表通过张贴形式
- 无法使用ajax序列化功能将图像插入数据库
- 使用ajax进行内联编辑(将值插入数据库)
- 将捕获的图像插入数据库问题(Cordova/SQlite/JavaScript)
- 如何在 PHP 中将动态表值插入数据库
- 将数据插入数据库express/mongodb应用程序时出错
- 通过API将视频信息插入数据库
- 我想单击一个
- 并获取 id 以通过 POST 将其插入数据库,可以吗?
- 如何将翻译后的文本插入数据库 php
- PHP-插入数据库而不刷新页面(OOP)
- MongoDB在将文档插入数据库之前为空集合
- 将本地存储值插入数据库