Saturday, 15 August 2015

javascript - How to capture data and send to server API using angular -


I am using angular for the first time and I am having problems sending back normal data to the server.

I have a server running on the API: http: // localhost: 8080 / lppayment which accepts POST requests and TokenId .

My JS looks like this and is successfully withdrawing a token from the stripe. I just want to send this token to the above mentioned API URL as a POST request.

How can I do this in angular?

'strict use'; Angular.module ('angularDjangoRegistrationAuthApp'). Controller ('TakeMoneyCtrl', function ($ radius, djangoAuth, valid) {$ scope.complete = false; djangoAuth.profile (). Then (function (data) {$ scope.model = data;}); $ scope.handleStripe = Function (status, response) {If there was an error, fix it. Warning ("Error")} Other {// found bar token, now charge it or smt token = response .id warning ("success:" + token);}}});

I just want to send the token to the server, when I successfully get back from the basket back. So I put a warning ("success"); But even that warning is not being shown on the page. Neither is the warning ("error"); However, on Chrome's Networks tab, I can see that the token is actually coming back from the bar. http: // localhost: 8080 / takepayment

question

how can I send the token received from the strip with my API call As an a POST request /

Requires angular $ http service () to inject it and then consume it in your controller Here is a simple example that consumes Kangaroo $ http and one POST

  Angular.module ('Angular digestrationships'). Controller ('techkrutkur', ['$ http', function ($ radius, $ http, DJ, auth, valid) {$ scope.complete = false; djangoAuth.profile (). Then (function (data) {$ scope.model = Data;}); $ Scope.handleStripe = function (position, response) {if (response.error) {// there was an error.} Please correct this. Warning ("Error")} Other {// founder token, You can put it in an object $ http.post var dataModel = {token: response.id}; // in a different service than your $ http post or priority. $ Http.post ('/ someUrl', JSON Error (function (Day (Status, data, position, header, config) {This callback will be called asynchronous / when response is available}.... Is called asynchronously if there is an error / / Server responds with error status.}); Warning ("success:" + token);}}}]);  

There is a way to do this above. But for this, call $ http in a different mascara service and NO Waiting for a response to finish using an JS promise or an expiry of time.

Create a new angular service to handle $ http

  Var app = angular.module ('Connection DegenerationAnthap App', []); App.service ('CommService', ['$ http', function ($ http) {this.processLoginToken = function (token) {var model = {token: token}} var promise = $ http.post ('/ api / Tokenproc ', JSON.stringify (model)) then (function (feedback) {return response.data;}, function (error) {console.log ("communication error, server not answered.");}); Return   

Now outside of your service, you will use it this way.

  var token = "02394924924929424 "; CommService.processLoginToken (token). Then (function (feedback) {// process of your reaction here}}, the function () {// server did not respond.});  

No comments:

Post a Comment