Ben CRUD yapıyorum ve benim arka uç için bazı veri göndermek istiyorsanız (node.js) o zaman bir hata alırsınız: angular.js:10765 POST http://localhost:1234/shop/removeProduct/574bf938b16158b40f9c87bc 400 (Bad Request)
senaryo:
$scope.removeProduct = function (partnerId, productId) {
$http.post("/campaign/removeProduct/" + partnerId, productId);
}
çözüm sadece basit paketi olan Bu böyle bir nesne parametresi (productId
):
$scope.removeProduct = function (partnerId, productId) {
$scope.productData = {productId: productId};
$http.post("/campaign/removeProduct/" + partnerId, $scope.productData);
}
Ama neden böyle yapmak zorunda? Bu arada, bu doğru mu yoksa farklı bir şekilde mi yapmalıyım?
@EDIT Bir şey daha, nasıl verilerinin yenilenmesi gerektiğini ekledim sonra/herhangi bir nesne kaldırıldı ? Bu doğru mu?
$scope.addPartner = function(data) {
$http({method: 'POST', url: addPartner, data})
.then(function(response) {
console.log(response);
});
$scope.loadPartnersData();
window.alert("Partner added!");
};
$scope.loadPartnersData = function() {
$http.get("/campaign/partner-list").then(function(result) {
$scope.partnerList = result.data.partnerList;
});
};
arka uç:
router.get('/partner-list', function (req, res) {
Partner.find({}, function (err, partnerList) {
if (err) throw err;
res.json({ partnerList: partnerList });
});
});
Neden sunucu kodu silmek gerçekleştirmek için yük w/o url ve yük hem arka uç kullanımını 'DELETE' fiil id Can ihtiyacı var –