我正在使用core-ajax来检索JSON数据.转动组件以作为JSON回发到服务器是另一回事.在所有情况下,无论传入的contentType或handleAs参数如何,看来我作为输入传入的JSON对象正在转换回服务器头中的key = value.
代码:
var ajax = document.querySelector('core-ajax');
ajax.method = 'POST';
ajax.handleAs = 'JSON';
ajax.contentType = 'application/json';
ajax.params = JSON.stringify(data);
ajax.go();
Run Code Online (Sandbox Code Playgroud)
真的很直白.Go中的日志给我:
2014/07/22 14:23:09 utils.go:139: OPTIONS /1/users/173?access_token=(token)
2014/07/22 14:23:09 utils.go:124: POST /1/users/173?access_token=(token)
2014/07/22 14:23:09 users.go:379: full_name=Greg%20Johnson
Run Code Online (Sandbox Code Playgroud)
我们已经确认我们方面没有发生任何转变.请求标题出来就好了.
我完全可能会遗漏一些东西.我们怎样才能成功发布JSON数据?
ebi*_*del 13
.params用于URL参数.你想要的是发布JSON作为请求体?为此,我相信你需要设置.body属性:
这应该做的伎俩:
ajax.body = data
Run Code Online (Sandbox Code Playgroud)
请参阅https://github.com/Polymer/core-ajax/blob/master/core-ajax.html#L151
| 归档时间: |
|
| 查看次数: |
3453 次 |
| 最近记录: |