你可以像一个独立的文件使用Ajax这样做 http://www.w3schools.com/jquery/jquery_ajax_get_post.asp
的PHP脚本:
首先,你的JavaScript文件:
$(document).on('click', '.dropdown-menu li a', function() {
var categoryName = $(this).html();
$.post("php-file.php",{cat_Name: categoryName});
});
,那么你的PHP file.php样子:
<?php
$categoryname = $_POST['cat_Name'];
$one = mysqli_query($con, "SELECT id FROM tb_category WHERE category_name = '?' ");
?>
如果要再次使用它们:
添加到您的PHP的结尾:
$return = new array();
$return[0] = ;//your results in this array
echo json_encode($return);
那么在你的JavaScript应该看起来像:
$(document).on('click', '.dropdown-menu li a', function() {
var categoryName = $(this).html();
$.post("php-file.php",{cat_Name: categoryName}, function(data){
sccess_function(data);}, "json");
});
再增加一个功能:
function succsess_function(data){
//do thing here
}
来源
2014-12-02 08:59:14
x1x
你可以做一个AJAX调用和数据发送到你的数据库查询涉及一个单独的PHP文件。 – aphextwix 2014-12-02 08:39:52