I'm having problems with laravel 4.1 sessions and unexpected behavior.
Depending on how I call the controller method, the session is working or not running my application on the POST route - to add items to the basket, which is the session. For some reason, the session is not being updated. However, if I call the same function with a GET request, the function works as expected.
My routes.phpcontains these two routes:
Route::get('testAdd', array('uses' => 'ProductsController@addToCart'));
Route::post('products/addToCart', array('uses' => 'ProductsController@addToCart'));
Both point to the same method.
Currently this method (for testing):
public function addToCart() {
Session::put("addcarttest", "add to cart");
return json_encode(Session::get('addcarttest'));
}
If I call a function with the POST method (with form data), I get the expected result and the contents of the session.
However, if I then check the session (using the profiler), it does not exist. No data was saved.
, GET, , , .
, , , POST , , , - GET sessin, POST, - POST .
- , .
- - , Laravel POST v GET? ?
, POST?
Update:
.
, URL-, , . jquery ajax , .
jquery :
$.ajax({
url: '/products/addToCart',
type: 'POST',
async: false,
})
.done(function() {
console.log("success");
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
return false;
async false - , . ( , true).
, submit ajax submit. - - .
? Jquery submit .