I'm trying to create a post using ajax in Laravel. Ajax apparently works, but when calling the controller, it doesn't have any data.
url: $(this).data("route"),
Has an URL and works perfectly.
var opciones = $("[name=cargaYDescarga]").bootstrapSwitch('state');
Returns false or true. I think there's not a problem with this data type. I need to return this data to the controller and do a SQL or other.
$('[data-click="state"]').on('switchChange.bootstrapSwitch', function () {
var opciones = $("[name=cargaYDescarga]").bootstrapSwitch('state');
console.log(opciones);
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
url: $(this).data("route"),
type: 'POST',
data: {opcion: opciones}
})
});
//Controller
public function opcion(Request $request)
{
dd($request->input('opcion'));
}
So, the question is: Do I have an error in this code? Ajax can´t pass true/false directly and I need to convert into a string?