JS:
$.ajax({
url: '/update',
data: ['a','b','c'],
type: 'POST'
})
Controller:
$input = Input::all();
var_dump($input);
die();
Output:
0: 1
1: 0
I'm trying to post an array from ajax and get it in Laravel, unfortunately it's not working. There are no problems with CSRF. Where am I going wrong?
your trying to send a js array so stringify it and send,
var data = {para : ['a','b','c'] };
$.ajax({
url: '/update',
data: JSON.stringify(data),
type: 'POST'
})
get the data in the controller,
$input = Input::json("para");
$firstElement = $input[0]; // prints a
$secondElement = $input[1]; // prints b
$thirdElement = $input[2]; // prints c
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.