jeudi 22 septembre 2016

Laravel ajax request not working for a foreach loop

I have collected some data in my controller.Now In my view,I have showed them inside a unordered list (ul) as a link.

<ul><li><a>....</a></li></ul>

Now When I am trying to fire an ajax request,only last data (i.e,Last link in listed items) is responding to the ajax request.The Ajax script is not inside the foreach loop.Do I have to place the ajax script inside the foreach loop.Then,for each data there will be a script.won't it create a problem?

<ul>
@foreach ($brands as $brand)

                <li class='n1'><a href=""  id=""></a></li>
            @endforeach

</ul>

my ajax script

<script>

**$('#').on('click',function(e){**

  e.preventDefault();

  $.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});


 $.ajax({

    type:"POST",
    url:'/userproduct',
     data: { value: $('#').attr('href')},
    success:function(data) {

   console.log(1);

    }

})

});



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire