Hi I have this ajax script:
function updatePage() {
if (request.readyState == 4) {
if (request.status == 200)
// get response array
var data = JSON.parse(request.responseText);
update_select($('select[name=island_name]'), data);
}
else if (request.status == 404) {
alert("Request url does not exist");
}
else {
alert("Error: status code is " + request.status);
}
}
The script executes fine but when it does I get an alert with ‘Error: status code is 200`. Why is the script entering this else block when the status is 200? What Can I do to prevent this?
The
if (request.status == 200)condition has no{.Therefore, its effect is just one line, and the chain of
elses apply to the outerif.If you indent it correctly, your code looks like this: