问问题
2654 次
3 回答
6
由于您已标记 jQuery,我假设您正在使用它。如果是这样,您可以这样做:
// attach a click handler for all links with class "like"
$('a.like').click(function() {
// use jQuery's $.post, to send the request
// the second argument is the request data
$.post('like.php', {post_id: this.id}, function(data) {
// data is what your server returns
});
// prevent the link's default behavior
return false;
});
关于您的第二个问题:不,除非您在 SSL (https) 中执行此操作,否则它并不能真正使其更安全。中间人仍然可以中途拦截您的消息并阅读内容。POST 比 GET 更间接(拦截和读取有效负载),但并不安全。
于 2013-04-24T14:46:24.820 回答
1
要使用 POST 发送类似的链接 ID,您可以执行以下操作:
$(document).ready(function() {
$("a.like").click(function(event) {
var data = event.target.id;
$.ajax({
type: "POST",
url: "like.php",
data: data
});
});
});
更新了,我的代码中有错字。
于 2013-04-24T14:49:58.277 回答
0
如果我正确理解你的问题,这样的事情应该适合你:
$('#link_22').click(function(){
var link = $(this).attr('id');
$.post('/like.php/', {post_id: link});
return false;
})
然后你可以通过 PHP 来达到这个目的:
$_POST['post_id'];
于 2013-04-24T14:47:26.227 回答