Ajax从链接中获取多个值

时间:2012-08-21 16:39:41

标签: php javascript jquery ajax

我有一个链接,我希望通过Ajax提交多个值。那么如何从此链接中选择streamitem_creator / target / content和type_id以传递到share.php?

echo"<a title='Share ".$poster_name['fullusersname']."s status' href='include/share.php?streamitem_creator=".$streamitem_data['streamitem_creator']."&streamitem_target=".$_SESSION['id']."&streamitem_content=".$streamitem_data['streamitem_content']."&streamitem_type_id=4'/>Share</a>";

我在链接

中提出了我的soloution用户数据

LINK

 echo'<a class="sharelink" title="Share '.$poster_name['fullusersname'].'s status" href="#"
     data-streamitem_creator='.$streamitem_data['streamitem_creator'].'
     data-streamitem_target='.$_SESSION['id'].'
     data-streamitem_content='.$streamitem_data['streamitem_content'].'
     data-streamitem_type_id=4>Share</a>';

AJAX

$(document).ready(function(){
$('.sharelink').click(function(e){

var streamitem_creator = $(this).data('streamitem_creator');
var streamitem_target = $(this).data('streamitem_target');
var streamitem_content = $(this).data('streamitem_content');
var streamitem_type_id = $(this).data('streamitem_type_id');

$.ajax({
type: "GET",
url: "../include/share.php",
data: { streamitem_creator: streamitem_creator, streamitem_target: streamitem_target, streamitem_content: streamitem_content, streamitem_type_id: streamitem_type_id }, 
success: function(msg){
$('#result').html(msg);
e.preventDefault(); 
}
});
});
}); 

1 个答案:

答案 0 :(得分:1)

要获取<a>元素href属性,您可以执行以下操作:

var link = $('a[href^="include/share.php?streamitem_creator"]').attr('href');

但使用ID会更具体,更简单。

要获取可以执行的查询字符串值数组:

var qs = link.split('?')[1].split('&');

但很难说这些查询字符串在PHP中是什么样的?