Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.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 但是为什么呢?_Javascript_Angularjs_Http_Stripe Payments_Http Status Code 400 - Fatal编程技术网

Javascript 但是为什么呢?

Javascript 但是为什么呢?,javascript,angularjs,http,stripe-payments,http-status-code-400,Javascript,Angularjs,Http,Stripe Payments,Http Status Code 400,当我在$scope.result=result.id时发送$scope.result时,我总是收到错误的JSON响应。当我传递result.id或$scope.result=result时传递$scope.result时,我得到404,没有找到。我正在尝试使用以下代码从Angular发布到我的Express服务器: angular.module('startupApp') .controller('stripeCtrl', function ($scope, $http) {

当我在$scope.result=result.id时发送$scope.result时,我总是收到错误的JSON响应。当我传递result.id或$scope.result=result时传递$scope.result时,我得到404,没有找到。我正在尝试使用以下代码从Angular发布到我的Express服务器:

angular.module('startupApp')
    .controller('stripeCtrl', function ($scope, $http) {

        $scope.stripeCallback = function (code, result) {
            if (result.error) {
                window.alert('it failed! error: ' + result.error.message);
            } else {
                window.alert('success! token: ' + result.id);
                $scope.result = result.id;
                $http.post('api/stripe', $scope.result)
                    .success(function (response) {
                    // not sure if anything goes here; not looking for a response.
                })
            }
        };
    });
我要传入的对象在JS控制台中如下所示:

Object {id: "tok_15cAbpL4TQAw2alUSkdXzIN5", livemode: false, created: 1425368309, used: false, object: "token"…}
卡:对象 客户ip:“76.126.66.106” 已创建:1425368309 id:“tokU CABPL4TQAW2ALUSKDXZIN5” livemode:false 对象:“令牌” 类型:“卡” 用法:false 原型:对象

我使用带条纹的角度付款

什么??????????????????????????????????????????? 更新: 这就是我在JS控制台中为前面的代码得到的全部内容

 GET http://localhost:9000/bower_components/lodash/lodash.js 404 (Not Found)
stripe.controller.js:15 Object {id: "tok_15cBUlL4TQAw2alUb8yGnalO"}
stripe.controller.js:16 Object {id: "tok_15cBUlL4TQAw2alUb8yGnalO"}
angular.js:9814 POST http://localhost:9000/api/stripe 404 (Not Found)
以及标题:

Remote Address:[::1]:9000
Request URL:http://localhost:9000/api/stripe
Request Method:POST
Status Code:404 Not Found
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:37
Content-Type:application/json;charset=UTF-8
Host:localhost:9000
Origin:http://localhost:9000
Referer:http://localhost:9000/stripe
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
Request Payloadview source
{id: "tok_15cBUlL4TQAw2alUb8yGnalO"}
id: "tok_15cBUlL4TQAw2alUb8yGnalO"
Response Headersview source
Connection:keep-alive
Content-Type:text/html
Date:Tue, 03 Mar 2015 08:35:16 GMT
Transfer-Encoding:chunked
Vary:Accept-Encoding
X-Powered-By:Express
以下是明确声明了响应头的更新:

angular.module('startupApp')
    .controller('stripeCtrl', function ($scope, $http) {

        $scope.stripeCallback = function (code, result) {
            if (result.error) {
                window.alert('it failed! error: ' + result.error.message);
            } else {
                window.alert('success! token: ' + result.id);
                $scope.result = result.id;
                console.log({id: result.id});
                console.log({id: $scope.result});
                //$http.post('api/card', $scope.card)
                var req = {
                    method: 'POST',
                    url: 'api/stripe',
                    headers: {
                        'Content-Type': application/json
                    },
                    data: {id: $scope.result}
                }
                $http.post(req)
                    .success(function (response) {
                    // not sure if anything goes here; not looking for a response.
                })
            }
        };
    });
这是JS控制台响应:

ReferenceError: application is not defined
    at Scope.$scope.stripeCallback (stripe.controller.js:22)
    at angular-payments.js:793
    at Scope.$get.Scope.$eval (angular.js:14384)
    at Scope.$get.Scope.$apply (angular.js:14483)
    at angular-payments.js:792
    at Object.Stripe.token.a.create.Stripe.request.success ((index):2)
    at Object.<anonymous> ((index):3)
    at Object.Stripe.a._receiveChannelRelay [as onMessage] ((index):2)
    at Object.Stripe.isDoubleLoaded.H.Socket.t.concat.incoming ((index):2)
    at f ((index):2)angular.js:11594 (anonymous function)angular.js:8544 $getangular.js:14485 $get.Scope.$applyangular-payments.js:792 (anonymous function)(index):2 Stripe.token.a.create.Stripe.request.success(index):3 (anonymous function)(index):2 Stripe.a._receiveChannelRelay(index):2 Stripe.isDoubleLoaded.H.Socket.t.concat.incoming(index):2 f
ReferenceError:未定义应用程序
在Scope.Scope.stripeCallback(stripe.controller.js:22)处
在angular payments.js:793
范围为$get.Scope.$eval(angular.js:14384)
在作用域$get.Scope.$apply(angular.js:14483)
在angular payments.js:792
位于Object.Stripe.token.a.create.Stripe.request.success((索引):2)
反对。((索引):3)
在Object.Stripe.a._receiveChannelRelay[as onMessage]((索引):2)
at Object.Stripe.isDoubleLoaded.H.Socket.t.concat.incoming((索引):2)
在f((索引):2)angular.js:11594(匿名函数)angular.js:8544$getangular.js:14485$get.Scope.$applyangular payments.js:792(匿名函数)(索引):2 Stripe.token.a.create.Stripe.request.success(索引):3(匿名函数)(索引):2 Stripe.a.\u receiveChannelRelay(索引):2 Stripe.isdoubleload.H.Socket.t.concat.incoming(索引):2 f

查看Angular发送的
内容类型
标题。有时,当它设置不正确时(即,它是“text/plain”并且serwer期望JSON),服务器将响应
404
。我有点不知道,内容类型头是什么?可能的,因为在这种情况下,您只是发送一个字符串(结果的id)。然后,您还可以尝试简单地将其更改为
$http.post('api/stripe',{id:$scope.result}
我试过了,但还是得到了404。我试过了几次。这是个好主意,也有道理,所以我不知道为什么它不起作用。我确定这个问题可能不值得你考虑,但我正在认真地努力做一些事情,尽我所能在我的孤独中学习。如果可以,请帮助我。