如何使用php在ajax中传递变量

如何使用php在ajax中传递变量,php,ajax,Php,Ajax,我想传递变量如下 $cat_d= $_POST["category_id"]; $results = $dbcon->prepare("SELECT all_post.post_name,all_post.description_,all_post.Id,category.cat_name FROM all_post INNER JOIN category ON category.Id=all_post.cat_Id where status_='VI

我想传递变量如下

$cat_d= $_POST["category_id"]; 

$results = $dbcon->prepare("SELECT   all_post.post_name,all_post.description_,all_post.Id,category.cat_name FROM  all_post  INNER JOIN category            
ON category.Id=all_post.cat_Id  where status_='VIEW' and cat_Id='$cat_d' ORDER BY Id DESC LIMIT $position, $item_per_page");
$results->execute();
我想从下面给出的分类页面代码中传递变量

<script src="js/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('#category_id').on('hidden',function(){
        var countryID = $(this).val();
        if(countryID){
            $.ajax({
                type:'POST',
                url:'../get_records.php',
                data:'category_id='+countryID,
                success:function(html){
                    $('#Sucategory').html(html);

                }
            }); 
        }else{
            $('#Sucategory').html('<option value="">Select category first</option>');

        }
    });


});
</script>

您应该尝试自己编写代码。如果您有问题,请发布您尝试过的内容,并清楚解释哪些内容不起作用,然后提供。读一个好问题。请务必阅读和阅读。是的,先生,我会提供详细信息。您的意思是要组织回音数据并在ajax端进行处理?对我来说,如果我有不止一种类型的分类数据,我更喜欢在PHP中使用json_编码,然后在Ajax上称赞它。我使用Ajax显示分页,但我想从分类页面获取id