0

我知道以前有人问过这个问题,但我试图应用答案但没有结果。

我正在尝试使用循环在同一个域上执行多个请求,for但它适用于我的数组的整个记录​​。

这是我使用的代码:

function showDesc(str) {
    var prod = document.getElementsByName("prod_item[]");
    var xhr = [], i;
    for (i = 0; i < prod.length; i++) {
        var txtHint = 'txtHint10' + i;  
        (function(i) {
            var xhr = new XMLHttpRequest();
            var url = "getDesc.php?q=" + str;

            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    document.getElementById(txtHint).innerHTML = xhr.responseText;
                }
            };
            xhr.open("GET", url, false);
            xhr.send();
        })(i);
    }
}

PHP

<select name="prod_item[]" id="prod_item.1" onchange="showDesc(this.options[this.selectedIndex].value)"></select>
<div id="txtHint100"></div>

然后我将使用动态表作为prod_item字段和div_id.

我的代码有什么错误吗?

4

0 回答 0