我有一个API调用,它接收到"Failed to load Resource“400错误。我已经尝试删除cookie和缓存,并使用不同的浏览器。当我看到图像大小可能是问题时,我也删除了一个图像。我读到了对HTTP头的需求,但不知道它将在我的代码中放在哪里,或者它看起来会是什么样子。任何帮助都将不胜感激!这是我的JS:
const app = document.getElementById('root');
const container = document.createElement('div');
container.setAttribute('class', 'container');
app.appendChild(container);
var request = new XMLHttpRequest();
request.open('GET', 'https://www.themuse.com/api/public/jobs', true);
request.onload = function () {
// Begin accessing JSON data here
var data = JSON.parse(this.response);
if (request.status >= 200 && request.status < 400) {
data.forEach(job => {
const card = document.createElement('div');
card.setAttribute('class', 'card');
const h1 = document.createElement('h1');
h1.textContent = job.title;
const p = document.createElement('p');
job.description = job.description.substring(0, 300);
p.textContent = `${job.description}...`;
container.appendChild(card);
card.appendChild(h1);
card.appendChild(p);
});
} else {
const errorMessage = document.createElement('marquee');
errorMessage.textContent = `Darn, it's not working!`;
app.appendChild(errorMessage);
}
}
request.send();发布于 2018-11-16 06:46:09
如果您尝试在浏览器中加载https://www.themuse.com/api/public/jobs,则会出现一个400错误以及以下错误消息:
{“代码”:400,“错误”:“不是‘页面’的有效参数”}
该页面要求您通过GET请求为其提供一个名为page的非空变量。
如果您将页面加载为https://www.themuse.com/api/public/jobs?page=1 (例如),则可以成功加载数据,您的问题就会消失!
https://stackoverflow.com/questions/53328794
复制相似问题