简体   繁体   中英

Send id with ajax and jquery

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");
                },              
        });
    });

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM