Reputation: 21
I'm using the polymer starter kit and I configured app.js file so it creates and iron-ajax element and send a call to the server to get data. Here is the code:
var _ajax = document.createElement('iron-ajax');
_ajax.url = 'url';
_ajax.headers = '{ "Authorization": "auth (number)"}';
_ajax.method = 'GET';
_ajax.handleAs = 'json';
_ajax.debounceDuration = 300;
_ajax.auto = true;
The error returned from this code tells me that "Authorization" in the headers is not passed through, but when I console log the iron-ajax element before the request I can see "Auth" in the headers. Am I doing something wrong in this code? What's the right way so the headers actually pass my server authentification. Note: tested the server with google "advanced REST api" it works fine with "Auth" set in the headers. (using slim php for REST server)
Upvotes: 2
Views: 698
Reputation: 5886
headers
expects an object, not a JSON string representing an object:
var _ajax = document.createElement('iron-ajax');
_ajax.url = 'url';
_ajax.headers = {"Authorization": "auth (number)"};
_ajax.method = 'GET';
_ajax.handleAs = 'json';
_ajax.debounceDuration = 300;
_ajax.auto = true;
Upvotes: 1