我正在向Ajax添加ID:
function callAjax()
{
jQuery.ajax({
type: "GET",
url: "topics.php?action=details&id=",
cache: false,
success: function(res){
jQuery('#ajaxcontent').html(res);
}
});
}
用这个:
<a href="javascript:;" id="'.$row['id'].'" class="button" onclick="callAjax();">'.$row['post_title'].'</a>
谢谢!
Try adding ...
data: { id: "MyIdHere" },
... this data is then formatted and sent correctly as a part of the GET.
This can be removed from the URL ... and also added as part of the data:
?action=details&id=
... like this ...
data: { action: "details", id: "MyIdHere" },
you can use:
url: "topics.php?action=details&id="+$('a').attr('id'),
if you want it to send in data.then use like this:
jQuery.ajax({
type: "GET",
url: "topics.php",
data: { action: "details", id: $('a').attr('id') },
cache: false,
success: function(res){
jQuery('#ajaxcontent').html(res);
}
});