请注意AJAX是客户端,所以你不能使用PHP你期待的结果的方式,你可以做如下
$('.select_item_category').click(function(){
var category_id = $(this).attr("category-id");
$.ajax({
url: window.location.href,
data: {
category_id : category_id
},
type: "GET",
/* Here is response you receive from server */
success: function(response){
$('#some_output_div').html(response);
/* See contents received */
alert(response);
}
})
});
和服务器端
<?php
if(isset($_GET['category_id']))
{
/* This is what you sent via ajax */
$category_value = $_GET['category_id'];
/* do your stuffs query whatever */
$some_response = 'This is what you send to browser';
echo $some_response;
die();
}
?>
请不要破坏你的帖子。一旦你发布了一个问题,它就一般属于Stack Overflow社区(在CC-by-SA许可下)。如果您想取消关联该帐户与您的帐户的关联,请参阅[解除关联请求的正确途径](http://meta.stackoverflow.com/q/323395/584192)? –