この質問が以前に尋ねられたことは知っていますが、回答を適用しようとしましたが、結果はありませんでした。
ループを使用して同じドメインで複数のリクエストを実行しようとしています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
。
私のコードに間違いはありますか?