【问题标题】:iron-ajax response function铁阿贾克斯响应函数
【发布时间】:2015-07-16 00:03:28
【问题描述】:

这行得通

        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() {  

  }

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

【问题讨论】:

    标签: polymer


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 好的去试试如果d.query和上例中的this.query一样
      • 不,它仍然不是我想要的聚合物 this.query 变量,试图让问题更清楚
      • 如果您只是希望查询包含响应,请设置 last-response="{{query}}"
      • no query 是对它获取的数据的查询,但 mbarney 发现解决方案要求将其粘贴到此处,但他不能,所以我会为他粘贴它
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-11
      • 1970-01-01
      • 1970-01-01
      • 2018-05-15
      相关资源
      最近更新 更多