hjælp til ajax
Hej eksperter jeg har problemer med nedenstående kode:function getHTTPObject(){
if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest) return new XMLHttpRequest();
else {
alert("Your browser does not support AJAX.");
return null;
}
}
function setOutput(elementId){
alert(httpObject.readyState);
if(httpObject.readyState == 4){
document.getElementById(elementId).innerHTML = httpObject.responseText;
}
}
function countryHasBeenChanged(){
document.getElementById('county_status_select').options[0].selected = true;
document.getElementById('county_status_select').disabled = true;
document.getElementById('city_status_select').options[0].selected = true;
document.getElementById('city_status_select').disabled = true;
document.getElementById('state_status_select').options[0].selected = true;
document.getElementById('state_status_select').disabled = true;
document.getElementById('address_field').value = '';
document.getElementById('address_field').disabled = true;
if(document.getElementById('country_status_select').value > 0){
httpObject = getHTTPObject();
if (httpObject != null) {
httpObject.open("GET", "AjaxHelper.php?country=" + document.getElementById('country_status_select').value, true);
httpObject.send(null);
httpObject.onreadystatechange = setOutput('state_div');
}
}
}
function stateHasBeenChanged(){
document.getElementById('city_status_select').options[0].selected = true;
document.getElementById('city_status_select').disabled = true;
document.getElementById('county_status_select').options[0].selected = true;
document.getElementById('county_status_select').disabled = true;
document.getElementById('address_field').value = '';
document.getElementById('address_field').disabled = true;
if(document.getElementById('state_status_select').value > 0){
httpObject = getHTTPObject();
if (httpObject != null) {
httpObject.open("GET", "AjaxHelper.php?state=" + document.getElementById('state_status_select').value, true);
httpObject.send(null);
httpObject.onreadystatechange = setOutput('county_div');
}
}
}
function countyHasBeenChanged(){
document.getElementById('city_status_select').options[0].selected = true;
document.getElementById('city_status_select').disabled = true;
document.getElementById('address_field').value = '';
document.getElementById('address_field').disabled = true;
if(document.getElementById('county_status_select').value > 0){
httpObject = getHTTPObject();
if (httpObject != null) {
httpObject.open("GET", "AjaxHelper.php?county=" + document.getElementById('county_status_select').value, true);
httpObject.send(null);
httpObject.onreadystatechange = setOutput('city_div');
}
}
}
function cityHasChanged(){
if(document.getElementById('city_status_select').value > 0){
document.getElementById('address_field').disabled = false;
}else{
document.getElementById('address_field').value = '';
document.getElementById('address_field').disabled = true
}
}
var httpObject = null;
Problemet opstår når jeg fjerner "alert(httpObject.readyState);", derefter insættes der ikke værdier i min html.