I am building a ecommerce project
in that , on index page product when i click on add To cart it should start a AJAX Request, it is going to class and fetching product id but i think not working ajax() method i.e sending url
button in index.blade.php
<button class="product_cart_button addcart"
data-id="" >Add to Cart</button>
script code for AJAX
<script type="text/javascript">
$(document).ready(function(){
$('.addcart').on('click',function(){
var id = $(this).data('id') ;
alert(id);
if(id){
$.ajax({
url: " / "+ id ,
type:"GET",
dataType : "json" ,
success:function(data){
alert('in success function');
alert(id) is working , but second alert not working
on server side
//Route::get('add/to/cart/{id}','CartController@AddCart');
Route::get('add/to/cart/{id}',function(){
return 'for testing url of ajax entering in web.php';
});
what may be problem I have two script for ajax , anathor for add to wishlist that is working fine , and this script is above that, even I tried it pasting below that but ordering not helping.
addToWishlist ajax code also has
$(document).ready(function(){
$('.addcart').on('click',function(){
these two same method can this be cause but i tried changing first function to functionTwo() even that not helping , Help Please
Aucun commentaire:
Enregistrer un commentaire