【发布时间】:2015-06-20 14:48:29
【问题描述】:
<dom-module id="my-new-app">
<style>
</style>
<template>
<iron-ajax
id="ajax"
handle-as="json"
content-type="application/json"
method="POST"
body={"user":2,"dob":"2015-06-10","jobs":1,"skills":[],"about":"cool"}
on-response="hresponse"
debounce-duration="3000">
</iron-ajax>
<button on-click="setajax">Click me</button>
</template>
<script>
Polymer({
is: "my-new-app",
setajax: function () {
this.$.ajax.url="http://127.0.0.1:8000/users/";
this.$.ajax.generateRequest();
},
hresponse: function(request) {
console.log(request.detail.response);
console.log(this.$.ajax.lastResponse);
console.log(this.$.ajax.params);
}
});
</script>
</dom-module>
这不会正确地将数据发布到服务器。此外,当我在 iron-ajax.html 文件中放入 console.log 时,我发现 contentType 仍然设置为 application/x-www-form-urlencoded 。文档说我们可以通过指定contentType = {String} 来指定内容类型。
【问题讨论】:
标签: polymer