Answer the question
In order to leave comments, you need to log in
Sending a GET request via AJAX gives me a 500 error. What can be wrong?
I'm trying to send an AJAX GET request:
$('document').ready(function(){
$('#plus').click(function(){
$.ajax({
method: 'GET',
url: '/cart?product_id=$item->id&decrease=1',
success: function(){
alert('Успешно');
},
});
});
$('#minus').click(function(){
$.ajax({
method: 'GET',
url: '/cart?product_id=$item->id&decrease=1',
success: function(){
alert('Успешно');
},
});
});
});
public function cart(){
$seo_title = 'Корзина';
$seo_discription = 'Корзина';
$seo_keywords = 'Корзина';
if (Request::isMethod('post')) {
$product_id = Request::get('product_id');
$size = Request::get('size');
$product = products::find($product_id);
$size = Db::table('sizes')->where('id', $size)->first();
Cart::add(array('id' => $product_id, 'name' => $product->title, 'qty' => 1, 'price' => $product->price, 'options'=>['image' => $product->image, 'sizes'=>$size->id ]));
}
//increment the quantity
if (Request::get('product_id') && (Request::get('increment')) == 1) {
$item = Cart::search(function($key, $value) { return $key->id == Request::get('product_id'); })->first();
Cart::update($item->rowId, $item->qty + 1);
}
//decrease the quantity
if (Request::get('product_id') && (Request::get('decrease')) == 1) {
$item = Cart::search(function($key, $value) { return $key->id == Request::get('product_id'); })->first();
Cart::update($item->rowId, $item->qty - 1);
if ($item->qty == 0) {
return redirect()->route('cart');
}
}
if ((Request::get('product_id')) && (Request::get('remove')) == 1){
Cart::destroy();
return redirect()->route('cart');
}
$cart = Cart::content();
return view('cart', array('cart' => $cart, 'title' => 'Welcome', 'description' => '', 'page' => 'home','seo_title'=>$seo_title,'seo_keywords'=>$seo_keywords,'seo_discription'=>$seo_discription));
}
Answer the question
In order to leave comments, you need to log in
Well, apparently id === "$item->id" is wrong.
Can you put the correct value there?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question