Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用AngularJs和PHP发布有效负载并接收响应_Javascript_Angularjs_Json - Fatal编程技术网

Javascript 使用AngularJs和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

这就是我试图将一些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");
$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");
        });
    }]);