laravel 使用 ajax 和 jquery 发送 id
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31244851/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Send id with ajax and jquery
提问by jc1992
Today I have a problem sending id with ajax and jquery ,I have a foreach in the view of laravel like this ,
今天我在用ajax和jquery发送id时遇到问题,我在laravel的视图中像这样有一个foreach,
<div class="ident" id="auctionIdentifier-{{$i}}" auction="{{$auction->id}}"></div>
this in the elements recieve correctly the id of auctions but when I try to doing a click I only send the first id.
这在元素中正确接收了拍卖的 id,但是当我尝试点击时,我只发送第一个 id。
I don't know when I doing a click in the next bid , I don't send the id corresponding. id}}">
我不知道我什么时候在下一次出价中点击,我不发送对应的id。id}}">
$(".inscription").click(function(){
console.log($(".ident").attr('auction'));
$.ajax({
url:'../bid/inscription',
dataType:'json',
type:'get',
cache:true,
success: function (response) {
console.log("ok");
},
});
});
回答by prototype
Maybe this helps:
也许这有帮助:
$(".ident").click(function(){
var id = $(this).attr('auction');
$.ajax({
url:'../bid/inscription',
dataType:'json',
type:'get',
cache:true,
data: {
id: id
},
success: function (response) {
console.log("ok");
},
});
});
Basically you need to get the currently clicked element auction attribute. Also you might want to add data-
in front of it like so: data-auction="VALUE"
. This way you can get it with $(el).data('auction')
.
基本上,您需要获取当前点击的元素拍卖属性。您也可能想像这样data-
在它前面添加:data-auction="VALUE"
. 这样你就可以用$(el).data('auction')
.