Javascript 使用Angular发布到APi

Javascript 使用Angular发布到APi,javascript,angularjs,api,post,Javascript,Angularjs,Api,Post,使用Angular的第一周,我现在尝试将其发布到第三方API 我想得到一些帮助,使这张表格张贴的数据正确,为额外的点,一些评论和期望在什么行正在做什么 我得到了这个错误 ReferenceError: formData is not defined at h.$scope.processForm (controller.js:116) at angular.js:10567 at angular.js:18627 at h.$eval (angular.js:1

使用Angular的第一周,我现在尝试将其发布到第三方API

我想得到一些帮助,使这张表格张贴的数据正确,为额外的点,一些评论和期望在什么行正在做什么

我得到了这个错误

 ReferenceError: formData is not defined
    at h.$scope.processForm (controller.js:116)
    at angular.js:10567
    at angular.js:18627
    at h.$eval (angular.js:12412)
    at h.$apply (angular.js:12510)
    at HTMLFormElement.<anonymous> (angular.js:18626)
    at angular.js:2780
    at q (angular.js:330)
    at HTMLFormElement.c (angular.js:2779)
我的控制器

// submit button controller POST
// =============================================================================
    .controller('formController', function ($scope, $http) {
        $scope.Fname = null;
        $scope.Lname = null;
        $scope.email = null;
        $scope.lblMsg = null;
        $scope.processForm = function (Fname, Lname, email) {
            var data = {
                Fname: formData.Fname,
                Lname: formData.Lname,
                email: formData.email,
                api_key: 0000,
                user_key: 0000
            };
//Call the services
            $http.post('https://API/do/create', JSON.stringify(data)).then(function (response) {
                if (response.data)
                    $scope.msg = "Post Data Submitted Successfully!";
            }, function (response) {
                $scope.msg = "Service not Exists";
                $scope.statusval = response.status;
                $scope.statustext = response.statusText;
                $scope.headers = response.headers();
            });
        };
    });

您的代码中应该有一些更改

1-声明
$scope.formData={}

2-移除

    $scope.Fname = null;
    $scope.Lname = null;
    $scope.email = null;
    $scope.lblMsg = null; 
因为您可以使用
$scope.formData
对象访问它们

3-将
formData.Fname
更改为
$scope.formData.Fname、
和其他类似内容

  $scope.formData = {};  // declare in controller



 var data = {
            Fname: $scope.formData.Fname,
            Lname: $scope.formData.Lname,
            email: $scope.formData.email,
            api_key: 0000,
            user_key: 0000
        };
4-您可以将
formData
对象传递给函数或不传递它。如果将
formData
传递给函数,请使用以下命令

ng click=“postdata(formData)”


您的代码中应该有一些更改

1-声明
$scope.formData={}

2-移除

    $scope.Fname = null;
    $scope.Lname = null;
    $scope.email = null;
    $scope.lblMsg = null; 
因为您可以使用
$scope.formData
对象访问它们

3-将
formData.Fname
更改为
$scope.formData.Fname、
和其他类似内容

  $scope.formData = {};  // declare in controller



 var data = {
            Fname: $scope.formData.Fname,
            Lname: $scope.formData.Lname,
            email: $scope.formData.email,
            api_key: 0000,
            user_key: 0000
        };
4-您可以将
formData
对象传递给函数或不传递它。如果将
formData
传递给函数,请使用以下命令

ng click=“postdata(formData)”


哈迪看起来棒极了。我将完成您的步骤并尝试实施,感谢您的测试,一旦成功,我将接受+1用于解释无错误,但发送或未发送时打印的功能不起作用。还有一些跨国公司,但我认为这只是当地的问题。接受答案,谢谢你的帮助。这是当地的问题。你可以找到更多关于交叉起源的信息。看起来很棒@Hadi。我将完成您的步骤并尝试实施,感谢您的测试,一旦成功,我将接受+1用于解释无错误,但发送或未发送时打印的功能不起作用。还有一些跨国公司,但我认为这只是当地的问题。接受答案,谢谢你的帮助。这是当地的问题。你可以找到更多关于交叉起源的信息。