<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}
来指定内容类型。聚合物1.0铁阿贾克斯不发布数据
我试图用聚合物1.0工作。我已经尝试使用stringify。我写的调试脚本在contentType中没有显示任何改变。 – ahumblenerd