我希望提交包含邮政编码的表单,该表单连接到api以解析以下页面,并从https://represent.opennorth.ca/postcodes/K2H6G7/
中提取特定邮政编码内的政客的每个实例。我一直在遵循本指南作为参考:https://represent.opennorth.ca/api/#postcode但是,当它运行时,没有任何返回。我在做什么错了?
var request = new XMLHttpRequest();
request.open('GET', 'https://represent.opennorth.ca/postcodes/K2H6G7/?format=apibrowser', true);
request.onload = function () {
// Begin accessing JSON data here
var data = JSON.parse(this.response);
if (request.status >= 200 && request.status < 400) {
data.forEach(representatives_centroid => {
console.log(representatives_centroid.first_name);
});
} else {
console.log('error');
}
}
request.send();