iron-ajax 响应函数
iron-ajax response function
这个有效
ready: function() {
this.response = function(e) {
if (e.target.status == 200) {
this.data = e.target.response
this.query = ''
}
}.bind(this)
var xhr = new XMLHttpRequest()
xhr.open("GET", "acp.json", true)
xhr.responseType = "json";
xhr.setRequestHeader("Content-Type", "application/javascript");
xhr.onload = this.response
xhr.send()
}
但我不知道如何将本地 this.query
绑定到像上面那样的 iron-ajax 响应?
<iron-ajax auto url="acp.json" last-response="[[data]]" on-response="response"></iron-ajax>
Polymer({
is:"acp-search",
query:"i need this",
response: function(e) {
if (e.target.status == 200) {
this.query = ''
}
},
ready: function() {
}
不起作用,查询仍未定义。
对于 iron-ajax
,当状态为 200 时调用响应函数,并且信息作为第二个变量的 属性 传入。
response: function(e,d) {
var myresponse = d.response;
console.log("the response is", myresponse);
}
e.target.status
未定义。使用 e.detail.xhr.status
这个有效
ready: function() {
this.response = function(e) {
if (e.target.status == 200) {
this.data = e.target.response
this.query = ''
}
}.bind(this)
var xhr = new XMLHttpRequest()
xhr.open("GET", "acp.json", true)
xhr.responseType = "json";
xhr.setRequestHeader("Content-Type", "application/javascript");
xhr.onload = this.response
xhr.send()
}
但我不知道如何将本地 this.query
绑定到像上面那样的 iron-ajax 响应?
<iron-ajax auto url="acp.json" last-response="[[data]]" on-response="response"></iron-ajax>
Polymer({
is:"acp-search",
query:"i need this",
response: function(e) {
if (e.target.status == 200) {
this.query = ''
}
},
ready: function() {
}
不起作用,查询仍未定义。
对于 iron-ajax
,当状态为 200 时调用响应函数,并且信息作为第二个变量的 属性 传入。
response: function(e,d) {
var myresponse = d.response;
console.log("the response is", myresponse);
}
e.target.status
未定义。使用 e.detail.xhr.status