1

我要做的是根据用户在前一个选择框中选择的内容来限制一个选择框的选项。它在 Chrome 和 Firefox 中完美运行,但在 IE 10 中唯一显示的是文本“未找到”。我不确定,但我的猜测是 request.status 出了点问题。然而,它是什么,我不知道。

function prepForms() {
for (var i = 0; i<document.forms.length; i++) {
    var thisform = document.forms[i];
    var departCity = document.getElementById("departcity");
    departCity.onchange = function() {
        var new_content = document.getElementById("ajaxArrive");
        if (submitFormWithAjax(thisform, new_content)) return false;
        return true;
    }
}
}

function getHTTPObject() {
if (typeof XMLHttpRequest == "undefined")
    XMLHttpRequest = function() {
        try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
            catch (e) {}
        try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
            catch (e) {}
        try { return new ActiveXObject("Msxml2.XMLHTTP"); }
            catch (e) {}
        return false;
    }
return new XMLHttpRequest();
}

function submitFormWithAjax(whichform, thetarget) {
var request = getHTTPObject();
if (!request) {return false;}
var dataParts = [];
var element;
for (var i = 0; i<whichform.elements.length; i++) {
    element = whichform.elements[i];
    dataParts[i] = element.name + "=" + encodeURIComponent(element.value);
}
var data = dataParts.join("&");
request.open("POST", "flightlocationfilter.asp#ajaxArrive", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.onreadystatechange = function() {
    if (request.readyState == 4) {
        if (request.status == 200 || request.status == 0) {
            var matches = request.responseText.match(/<div id="ajaxArrive">([\s\S]+)<\/div>/);
            if (matches.length > 0) {
                thetarget.innerHTML = matches[1];
            } else {
                thetarget.innerHTML = "<p>--Error--</p>";
            }
        } else {
            thetarget.innerHTML = "<p>" + request.statusText + "</p>";
        }
    }
};
request.send(data);
return true;
};

编辑:使用 IE 开发人员工具完成后,看起来 request.readyState 没有超过 1 到 4。

4

0 回答 0