好的我正在尝试从前端(Angular)发送数据,然后将数据发送到支持的(节点)。
我还需要通过发送包含我的email
,password
和user_key
的帖子来验证我的第三方API,即获取我的API密钥,一旦发布我应该获得临时api_key
。
然后我使用此密钥和我重试的数据(来自前端)发布API端点。
我有点迷失,对角度和节点都不熟悉。
我需要帮助处理一些事情
api_key
)Fname
,Lname
,email
,user_key
,api_key
)我使用了为发送到here
的API发送的npm包这是我必须去的地方,任何帮助都会很好。
支持服务器/ index.js
// First Get Posted variables
// Code HERE
// Now authenticate the api and get api_key
var pardot = require('pardot');
pardot({
email: 'tom@mail.co.uk',
password: 'Password',
userKey: '345636345345'
})
.then(function (client) {
// We've successfully authenticated.
// Perform some action
client.prospects.create(email, params, {
email: 'test',
Fname: 'tom',
Lname: 'boom'
});
}).fail(function (err) {
// Failed to authenticate
alert('failed')
});
前端帖子`
FirstModule.controller('formController', function ($scope, $http) {
$scope.formData = {};
$scope.processForm = function (Fname, Lname, email) {
var data = {
Fname: $scope.formData.Fname,
Lname: $scope.formData.Lname,
email: $scope.formData.email,
};
//Call the services
$http.post('server/index', JSON.stringify(data)).then(function (response) {
if (response.data)
$scope.formData = "Post Data Submitted Successfully!";
}, function (response) {
$scope.formData = "Post Data Submitted Failed";
$scope.statusval = response.status;
$scope.statustext = response.statusText;
$scope.headers = response.headers();
});
};
});`
请求HTML
<form name="myForm" id="signup-form" class="col-sm-8 col-sm-offset-2"
ng-submit="processForm()"
ng-click="postdata(formData)">
<div class="form-group">
<label for="first-name">First Name*</label>
<input type="text" class="form-control col-sm-12" name="Fname" placeholder="Enter first name"
ng-model="formData.Fname"
ng-required="true">
<span ng-if="!myForm.Fname.$invalid" class="glyphicon glyphicon-ok " style="color: green" aria-hidden="true"></span>
</div>
<div class="form-group">
<label for="first-name">Last Name*</label>
<input type="text" class="form-control col-sm-12" name="Lname" placeholder="Enter last name"
ng-model="formData.Lname"
ng-required="true">
<span ng-if="!myForm.Lname.$invalid" class="glyphicon glyphicon-ok " style="color: green" aria-hidden="true"></span>
</div>
<div class="form-group">
<label for="first-name">Email*</label>
<input type="email" class="form-control col-sm-12" name="email" placeholder="Enter valid E-mail"
ng-model="formData.email"
ng-required="true">
<span ng-if="!myForm.email.$invalid" class="glyphicon glyphicon-ok " style="color: green" aria-hidden="true"></span>
</div>
</form>