Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要帮助Ajax/Javascript吗_Javascript_Html_Ajax - Fatal编程技术网

需要帮助Ajax/Javascript吗

需要帮助Ajax/Javascript吗,javascript,html,ajax,Javascript,Html,Ajax,我在这件事上被难住了。我将使用Onclick函数获得未知数量的隐藏和未隐藏(取决于用户在我的数据库中拥有的信息量)。当单击每个未隐藏的div时,我通过AJAX传递它们的值,并从php文件中获取一些文本 function selectProduct(index) { var option = document.getElementById('sel'+index).value; var queryStringOne = "?option="+option;

我在这件事上被难住了。我将使用Onclick函数获得未知数量的隐藏和未隐藏(取决于用户在我的数据库中拥有的信息量)。当单击每个未隐藏的div时,我通过AJAX传递它们的值,并从php文件中获取一些文本

     function selectProduct(index) {
   var option = document.getElementById('sel'+index).value;
        var queryStringOne = "?option="+option;
         http.open("GET", "product.php" + 
                          queryStringOne, true);
        http.onreadystatechange = getHttpResOne+index;
          http.send(null); 
    }

    function getHttpResOne(index) {

      if (http.readyState == 4) { 
       resOne = http.responseText;  // These following lines get the response and update the page
  document.getElementById('prohidden'+index).innerHTML = resOne;    
   }
 }
HTML

选择项目
选择项

我需要单击每个div的响应文本,以替换其正下方隐藏的div。将(索引)传递到getHttpRequestOne()函数时遇到问题。

您始终可以向本机对象添加自定义属性。这可能不是最好的办法。但是你可以试试这个

function selectProduct(index) {
    var option = document.getElementById('sel'+index).value;
    var queryStringOne = "?option="+option;
    http.open("GET", "product.php" + 
              queryStringOne, true);
    http.onreadystatechange = getHttpResOne;
    http.myCustomValue = index;
    http.send(null); 
}

function getHttpResOne() {
    if (http.readyState == 4) { 
    resOne = http.responseText;  // These following lines get the response and update the page
    var index = http.myCustomValue;
    document.getElementById('prohidden'+index).innerHTML = resOne;    
    }
}
function selectProduct(index) {
    var option = document.getElementById('sel'+index).value;
    var queryStringOne = "?option="+option;
    http.open("GET", "product.php" + 
              queryStringOne, true);
    http.onreadystatechange = getHttpResOne;
    http.myCustomValue = index;
    http.send(null); 
}

function getHttpResOne() {
    if (http.readyState == 4) { 
    resOne = http.responseText;  // These following lines get the response and update the page
    var index = http.myCustomValue;
    document.getElementById('prohidden'+index).innerHTML = resOne;    
    }
}