我正在摆弄 Polymer,我正在尝试创建一个简单的 get 请求来检索我的 Github 信息。我正在检索错误 Polymer.httpRequest is not a function
。显然是这样。
Polymer({
is: 'custom-element',
properties: {
name: ''
},
httpRequest: function(type, url){
var getRequest = new XMLHttpRequest();
var data = getRequest.responseText;
getRequest.open(type, url, true);
getRequest.send();
console.log(data);
return data;
}
});
Polymer.httpRequest('GET', 'https://api.github.com/users/joshspears3');
有什么想法为什么会返回此错误吗?感谢您提前提供的帮助。
最佳答案
Polymer 没有您创建的 httpRequest 方法。相反,该方法是为“自定义元素”创建的。
您可以访问如下所示的新元素上的方法:
<link rel="import" href="../polymer/polymer.html">
<dom-module id="custom-element">
<template></template>
<script>
Polymer({
is: 'custom-element',
properties: {
name: ''
},
ready: function () {
this.httpRequest('GET', 'http://stackoverflow.com');
},
httpRequest: function(type, url){
var getRequest = new XMLHttpRequest();
var data = getRequest.responseText;
getRequest.open(type, url, true);
getRequest.send();
console.log(data);
return data;
}
});
</script>
</dom-module>
关于javascript - 不是功能错误, polymer ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32935924/