表css属性不改变ajax调用后


Table css property not changing after ajax call

最初我的表显示是none所以它不可见在我的应用程序中,我使用ajax调用,所以当用户选择任何选项表生成和initiall显示属性设置为none更改为块,它变得可见,但我的表是不可见的。请建议。

Ajax工作得很好,只是显示属性没有改变

JAVASCRIPT代码

function checkbrand(str) {
    document.getElementById("first").style.display="block";
    if (str == "") {
        document.getElementById("brand").innerHTML = "";
        return;
    } else { 
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("brand").innerHTML = xmlhttp.responseText;
            }
        };
        xmlhttp.open("GET","test1.php?m="+str,true);
        xmlhttp.send();
    }
}
PHP代码

     <?php
        session_start();
       require('connect.php');
       $m = $_GET['m'];
       $skuarray=array();
       $p=$_SESSION['Head_item_id'];
        $sql="SELECT * FROM `major_item_table` where Head_item_id=$p";
$query=$handler->query($sql);
echo '<select id="category" onchange="checkbrand(this.value)";>';
echo '<option selected="selected">Select SubCategory</option>';
while($r=$query->fetch())
{   
    echo "<option>". $r['Major_item_name']."</option>";
}
echo '</select>';
        echo '<div id="first" style="display:none">'; 
        echo '<table>
        <tr>
        <th>SKU</th>
        <th>Vendor_Id</th>
        <th>Rates_Entered</th>
        <th>Rate_Shown_On_Website</th>
        <th>Date_Time</th>
        <th>Rate_Type</th>
        </tr>';
        echo '</table>';
      ?>

试试这个:

function checkbrand(str) {
   document.getElementById("first").style.display="block";    
   if (str == "") {
}// End of function
setInterval(function(){checkbrand(str)},1000);//You can pass your argument by yourself

您需要使用setInterval。它在一段时间间隔后调用这个函数。这里我设置了1秒,你可以试试这个。