mardi 24 juillet 2018

i am using laravel 5.4 and from submission using ajax

laravel form code @foreach($products as $product) <form action="" method="post"> <input type="text" name="img" value="{!! $product->product_image !!}" id="img{!! $product->product_image !!}"> <input type="text" name="price" value="{!! $product->product_price !!}" id="price{!! $product->product_price !!}"> <input type="text" name="name" value="{!! $product->product_name !!}" id="pro_name{!! $product->product_name !!}"> <input type="text" name="id" value="{!! $product->id !!}" id="pro_id{!! $product->id !!}"><br> <!--<input id="form-control" type="number" max="10" min="1" class="form-control" name="qty" value="1">--> <div class="col-lg-1"></div> <div class="col-lg-3 col-xs-4"> <select class="select_val" id="form-control{!! $product->id !!}" name="qty" > <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> </div> <div class="col-lg-3 col-xs-6"> <button type="submit" class="btn btn-primary" id="addtocart<?php echo $product->id ?>"> <i class="fa fa-shopping-cart"></i> &nbsp;Add-to-cart </button> </div> </form> @endforeach

javascript code ` jQuery(document).ready(function() {

@foreach($products as $product)

  jQuery('#addtocart{!! $product->id !!}').on('click',function(e){

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

        e.preventDefault();

    var  pro_name  = $('#pro_name{!! $product->product_name !!}').val();

    var  id   = $('#form-control{!! $product->id !!}').val(); 

    var  image  = $('#img{!! $product->product_image !!}').val();

    var  price  = $('#price{!! $product->product_price !!}').val();

     alert("qty-"+id+"-"+pro_name+"-"+"-"+image+"-"+price);

  }); 
@endforeach   

});` its my form

another image is alert box

i am not getting proper value price and image name in alert box 

i am using laravel 5.4 and from submission using ajax

how to get rid of this errors



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire