Reputation: 40
This here is my iron-ajax element inside a dom-module: This here is my javascript:
var iron_ajax = document.querySelector('iron-ajax');
iron_ajax.body = {"full_names":profile.getName(),"access_token":googleUser.getAuthResponse().id_token};
iron_ajax.generateRequest();
When I grab the $_POST variable and dump the contents to a file (after encoding them as json) I get [] (That means no data, zero, nothing). When I .log() the variables before sending them to ensure I'm not sending blanks, the values do appear, so it's not that I'm sending blanks. I think it's a bug, or I just don't understand how it works. Can someone please help. Thanks.
Upvotes: 0
Views: 1779
Reputation: 46
I found a solution. This is not a Polymer problem. When you POST with content type JSON $_POST will not populate. Try this at server side:
$json = file_get_contents("php://input");
$_POST = json_decode($json, true);
Now your POST-Array will be filled with your request data.
Upvotes: 3
Reputation: 87
I would like to know what is in your iron-ajax function, but here is what I have and it works.
<iron-ajax auto url="http://localhost:11111/api/Test" headers='{"Accept": "application/json"}' handle-as="json" on-response="ajaxResponse"></iron-ajax>
...
ajaxResponse: function (event) {
this.response = event.detail.response;
}
Upvotes: 0