0

I have a Python script which sends some events on server. Code looks like this:

LOGGER = logging.getLogger("send_event")
POST_EVENT_URL = "http://localhost:3000/event/"

def send(name, data):
   url = POST_EVENT_URL + name
   headers = {'content-type': 'application/json'}
   auth = None

   r = requests.post(url, auth=auth, data=json.dumps(data), headers=headers, verify=False)

   if (not r.ok) or (200 > r.status_code > 299):
       raise IOError(("Failed to upload session to server. OK %s HTTP        response code: %d" % (r.ok, r.status_code)))

I need to pass 2 params to this Python function, one will be string(name) and other is json(data) can someone please help me to figure out how to do this using AngularJS 1? Is it possible at all?

Thanks!

1 Answer 1

1

use $http to send http request. First inject $http to controller and implement like this

 angular.module("app",[])
.controller("ctrl",function($scope,$http){
    var POST_EVENT_URL = "http://localhost:3000/event/";
    $scope.send  = function(name, data){

        var url = POST_EVENT_URL + name;
        var headers = {'content-type': 'application/json'};

        $http({
            url : url,
            method : "POST",
            headers : headers,
            data : data
        }).then(function(response){
            //success
        },function(resonse){
            //error 
        })

    }
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.