Javascript 使用AngularJs和PHP发布有效负载并接收响应
这就是我试图将一些JSON发布到php文件的方式Javascript 使用AngularJs和PHP发布有效负载并接收响应,javascript,angularjs,json,Javascript,Angularjs,Json,这就是我试图将一些JSON发布到php文件的方式 $http({method: 'POST', url: ApiService.Url("checkout.php"), data: "My JSON payload", cache: false}); 这是我想发布到的PHP文件 <?php // Retrieve the request's body and parse it as JSON $input = @file_get_contents("php://input"); $eve
$http({method: 'POST', url: ApiService.Url("checkout.php"), data: "My JSON payload", cache: false});
这是我想发布到的PHP文件
<?php
// Retrieve the request's body and parse it as JSON
$input = @file_get_contents("php://input");
$event_json = json_decode($input);
// header('Content-Type: application/json');
echo "MAMAMAMAMAMAAMAMAMAMAMAMAMMA";
欲了解更多信息,请点击此处
我希望这对你有帮助
I am creating a function that will post data to the server and inform you with the response.
var ajaxApp = angular.module("ajaxApp", []);
ajaxApp.controller("CompaniesCtrl", ['$scope', '$http', '$q', function($scope,
$http, $q) {
// This function will take params object as a parameter, will make a post
//request to the server and return the promise.
var postData = function (params) {
var deferred = $q.defer();
var post = $http({
method: "POST",
url: "YOUR_URL",
dataType: 'json',
data: params,
headers: { "Content-Type": "application/json" }
});
post.success(function (data, status) {
deferred.resolve(data);
});
post.error(function (data, status) {
deferred.reject(null);
});
return deferred.promise;
};
postData().then(function(data) {
// This function will be executed when api call is success
console.log("Data posted");
console.log(data);
}, function() {
// This function will be executed when api call fails.
console.log("Error Occured");
});
}]);