Alan Smith
Posts: 0
Joined: Tue Jun 10, 2014 4:59 pm

Passing a global scope variable into service request header

I'm trying to pass a global scope variable into a service header, but I'm not sure on the syntax for this?

I am using an Ionic server code POST request, and I am trying to pass a token via the Authorization header. I cannot seem to use a $scope variable.

The variable on my index page is: auth.

The variable on the model is authtoken

So, this is my sever code:

var url = "URL";

var XHRResponse = XHR2.send("POST", url, {
"headers": {
"Authorization": $scope.auth.token,
},
"body": ""
});

Apperyio.response.success(XHRResponse.body, "application/json");

What is the correct syntax for adding the global variable to the server code request header?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Passing a global scope variable into service request header

Hello Alan,

Do you use this code in the Server Code or in the application?
XHR2, Apperyio.response.success - samples from the Server Code
$scope.auth.token - from the Ionic app

So it seems you've mixed up them.

Alan Smith
Posts: 0
Joined: Tue Jun 10, 2014 4:59 pm

Passing a global scope variable into service request header

Hi Serhii

I have a global variable that I need to send via server code. I have an auth token, saved as a global variable.

How do i send this via server code to the service in the header?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Passing a global scope variable into service request header

The global variable is global only in the application, so it is not available in other applications neither in Server Codes.

Please send it as a parameter to the server code and read it there with the code:
https://docs.appery.io/reference#serv...
prevar token = request.get();/pre

Return to “Issues”