Answer the question
In order to leave comments, you need to log in
How to check if a JSON file exists?
Hello.
Task: if A.json does not exist, load B.json
Why won't my bike move? Thank you.
https://jsfiddle.net/kukaew/16dqjx5g/
function cursArr() {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'A.json', false);
xhr.send();
if (xhr.status != 200) {
xhr.open('GET', 'B.json', false);
xhr.send();
return JSON.parse(xhr.responseText);
}
else {
return JSON.parse(xhr.responseText);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question