铁 - 阿贾克斯响应函数

时间:2015-07-16 00:03:28

标签: polymer

这有效

        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绑定到像上面这样的铁-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() {  

  }

不起作用,查询仍未定义。

2 个答案:

答案 0 :(得分:3)

e.target.status未定义。使用e.detail.xhr.status

答案 1 :(得分:1)

对于iron-ajax,当状态为200并且信息作为第二个变量的属性传入时,将调用响应函数。

response: function(e,d) {
  var myresponse = d.response;
  console.log("the response is", myresponse);
}
相关问题