我想将链接中的两个变量传递给我的jQuery Ajax函数。但我不知道如何做这些Ajax的东西。如何将PHP变量从链接传递给jQuery ajax函数
我有两个ID的链接。 1. rowid & 2nd。 BOOKID。 我必须将这两个id传递给我的jquery函数。
请帮我,我该如何做到这一点。
`//cart item displaying in a for each loop , each row have a 'remove' link with two id
//say i have $id='4dsf2323' & $bid='43' now i have to pass these two ids to my jquery function on click of a link
<a id="removeid" >Remove item from cart link</a>`
我的jQuery函数
<script>
$('removeid').click(function(e) {
// prevent the default action when a nav button link is clicked
e.preventDefault();
//HOW TO GET HERE THOSE TWO IDS FROM MY ABOVE LINK ON CLICK EVENT
// ajax query to retrieve the HTML view without refreshing the page.
$.ajax({
type: 'get',
url: '/path/to/your/controller/method',
dataType: 'html',
success: function (html) {
// success callback -- replace the div's innerHTML with
// the response from the server.
$('#yourDiv').html(html);
}
});
});
</script>
***********更新************** 输出看起来像这样
嗯,第二个id在哪里?每个html元素可能只有一个ID。 请澄清你需要什么,并告诉我们你的HTML布局。此外,你的'$('removeid')。click(function(e){'不会工作,它应该被重写为'$('#removeid')。click(function(e){' – varnie 2013-03-05 15:30:40