javascript - Send id with ajax and jquery - Stack Overflow

Today I have a problem sending id with ajax and jquery ,I have a foreach in the view of laravel like th

Today I have a problem sending id with ajax and jquery ,I have a foreach in the view of laravel like this ,

<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.

I don't know when I doing a click in the next bid , I don't send the id corresponding. 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");
                },              
        });
    });

Today I have a problem sending id with ajax and jquery ,I have a foreach in the view of laravel like this ,

<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.

I don't know when I doing a click in the next bid , I don't send the id corresponding. 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");
                },              
        });
    });
Share Improve this question asked Jul 6, 2015 at 11:36 jc1992jc1992 6443 gold badges10 silver badges26 bronze badges 1
  • what happens when you click second time? – Rishi Prakash Commented Jul 6, 2015 at 11:38
Add a ment  | 

1 Answer 1

Reset to default 4

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').

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744383121a4571529.html

相关推荐

  • javascript - Send id with ajax and jquery - Stack Overflow

    Today I have a problem sending id with ajax and jquery ,I have a foreach in the view of laravel like th

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信