【发布时间】:2015-09-16 18:22:04
【问题描述】:
我使用引导程序创建了切换下拉菜单。使用 ajax 调用填充下拉菜单项。 ajax 请求调用 PHP 脚本,该脚本从数据库中获取值并填充下拉菜单项。我使用无序列表在下拉菜单中显示项目。当我单击负责 ajax 调用的按钮时,项目正在被填充但有延迟。当我再次单击该按钮时,没有观察到延迟。
JQuery:
$(document).on('click',"#itemsButton",function (e) {
e.preventDefault();
var osn = $("#osn").val();
//$("#items-dropdown").empty();
var dataString = 'searchString=' + osn;
if ($.trim(osn).length > 0) {
$.ajax({//create an ajax request to load_page.php
type: "POST",
url: "retrieveItemsOrdered.php",
data: dataString,
cache: false,
dataType: "html", //expect html to be returned
success: function (html) {
$("#items-dropdown").html(html);
}
});
}
});
HTML:
<div class='itemsmenu btn-group'>";
<button type='button' class='btn dropdown-toggle' data-toggle='dropdown' id='itemsButton'>
<span class=>Click here to view items </span>
<span class='pull-right'><i class='fa fa-caret-down'></i></span>
</button>
<ul class='dropdown-menu ' role='menu' id='items-dropdown'>
</ul>
</div>
PHP:
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo "<li class='ordeinfo-style'>";
echo "<b>".$row['sku']."</b>";
echo "</li>";
}
CSS:
.dropdown-menu {
border-radius: 0;
-webkit-box-shadow: none;
box-shadow: none
}
.itemsmenu .btn{
text-align: center;
}
ul {
min-width: 200px;
}
.items-dropdown{
text-align: center;
}
ul b{
font-weight: normal;
display: inline block;
font-size: 16px;
font-weight: bolder;
color: #000;
}
.quantity{
font-size: 16px;
margin-right: 20px;
color: #000;
}
请让我了解为什么我在第一次单击按钮以显示下拉菜单项时遇到延迟
【问题讨论】: