PolymerElements iron-ajax not posting data

大城市里の小女人 提交于 2019-12-12 02:57:45

问题


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.


回答1:


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.




回答2:


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;
}


来源:https://stackoverflow.com/questions/30661155/polymerelements-iron-ajax-not-posting-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!