这是我用于显示类别选择选项的HTML代码:
<select class="form-control" name="parent_category" id="parent_category">
<option value="parent">Parent</option>
<?php while ($parent = mysqli_fetch_assoc($parentresult)) : ?>
<option value="<?=$parent['id'];?>"><?=$parent['category_name']; ?>
</option>
<?php endwhile; ?>
</select>
这是类别删除的jQuery
function removecategory(cat_id){
var removecategory = '';
jQuery.ajax({
url : '/multivendor/dashboard/parser/ajax.php',
method : 'POST',
data : {cat_id: cat_id, removecategory : 1},
success : function(data){
var result = JSON.parse(data);
if ( result.status == "parentdelete" ) {
location.reload(true);
} else if( result.status == "childdelete"){
$("#"+ cat_id).fadeOut("slow", function() { $(this).remove(); });
}else{
alert("something went row");
}
},
error : function(){ alert("something went wrong");}
});
}
我正在使用重新加载来重新加载与父级类别进行选择
我只想重新加载或刷新选择,从而为我提供当前数据库类别的值。
这是可能的吗?
如果可能的话,使用清晰的ajax。创建DIV,其中包含您创建的元素:
<div class="select"> // the div will place where you want to put the select
</div>
php文件" get_select.php"如下:
<select class="form-control" name="select_data" id="select_data">
<option value='0'></option>
<?php
require_once("Connection.php");//here you put your connection to database
$query = mysqli_query($link,"//link is my connection variable
//all your mysql query
");
while($row = mysqli_fetch_array($query)){
echo "<option value=$row[row_name_database]>$row[alias_of_your_values ]</option>";
}
?>
</select>
索引页面具有以下AJAX代码:
<script>
$(document).ready(function(){
load_select();//loading the document updates it
});
function load_select(){
var parameters = {"action":"ajax"};
$.ajax({
url:'get_select.php', //we call our php file that calls the data
type: "POST",
data: parameters,
beforeSend: function(object){
},
success:function(data){
$(".select").html(data).fadeIn('slow');//we refer to our div by its class
}
})
}
function removecategory(cat_id){
var removecategory = '';
jQuery.ajax({
url : '/multivendor/dashboard/parser/ajax.php',
method : 'POST',
data : {cat_id: cat_id, removecategory : 1},
success : function(data){
var result = JSON.parse(data);
load_select();//load the select with the desired elements
},
error : function(){ alert("something went wrong");}
});
}
</script>