Javascript 如何使用php和angular js在http上发布ngCart签出按钮?
我不知道如何将数据发布到新的php页面,以下是我的代码:Javascript 如何使用php和angular js在http上发布ngCart签出按钮?,javascript,php,angularjs,git,Javascript,Php,Angularjs,Git,我不知道如何将数据发布到新的php页面,以下是我的代码: <ngcart-checkout service="http" settings="{ url:'./checkout.php' }">Checkout </ngcart-checkout> 因此,我的问题是如何将我的checkout按钮重定向到checkout.php,以及如何使用http post将这些项目发布到checkout.php?我想您可能正在ngcart.js文件中寻找类似的内容 <s
<ngcart-checkout service="http" settings="{ url:'./checkout.php' }">Checkout </ngcart-checkout>
因此,我的问题是如何将我的checkout按钮重定向到checkout.php,以及如何使用http post将这些项目发布到checkout.php?我想您可能正在ngcart.js文件中寻找类似的内容
<script>
.service('ngCart.fulfilment.log', ['$http', 'ngCart', function($http, ngCart){
this.checkout = function(settings){
//var item_data = ngCart['$cart']['items'], message;
//return $http.post('checkout.php',
// {data:item_data});
var postData = 'item_data='+JSON.stringify(ngCart['$cart']['items']);
$http({
method : 'POST',
url : 'checkout.php',
data: postData,
headers : {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(res){
console.log(res);
}).error(function(error){
console.log(error);
});
}
}])</script>
.service('ngCart.implementation.log',['$http','ngCart',函数($http,ngCart){
this.checkout=功能(设置){
//var item_data=ngCart['$cart']['items'],消息;
//返回$http.post('checkout.php',
//{data:item_data});
var postData='item_data='+JSON.stringify(ngCart['$cart']['items']);
$http({
方法:“POST”,
url:'checkout.php',
数据:postData,
标题:{'Content-Type':'application/x-www-form-urlencoded'}
}).成功(功能){
控制台日志(res);
}).错误(函数(错误){
console.log(错误);
});
}
}])
谢谢,但我如何使用php发布此内容?很抱歉,我是编程方面的新手,尤其是在将数据传输到php时。这将在您的浏览器中将购物车数据解析为json,我还试图解决如何在结帐时通过电子邮件发送购物车数据:)
<button class="btn btn-primary" ng-click="checkout()" ng-disabled="!ngCart.getTotalItems()" ng-transclude>Checkout</button>
.service('ngCart.fulfilment.http', ['$http', 'ngCart', function($http, ngCart){
this.checkout = function(settings){
return $http.post(settings.url,
{data:ngCart.toObject()})
}
}])
<script>
.service('ngCart.fulfilment.log', ['$http', 'ngCart', function($http, ngCart){
this.checkout = function(settings){
//var item_data = ngCart['$cart']['items'], message;
//return $http.post('checkout.php',
// {data:item_data});
var postData = 'item_data='+JSON.stringify(ngCart['$cart']['items']);
$http({
method : 'POST',
url : 'checkout.php',
data: postData,
headers : {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(res){
console.log(res);
}).error(function(error){
console.log(error);
});
}
}])</script>