Why can't I get the Ajax request? I have a ProductController with a create()
method.
public function create(Request $request)
{
$value = $request->get('keyname') ? $request->get('keyname') : 1;
$companies = Company::all();
$categories = Company::find($value)->categories;
return view('admin.pages.createProduct', compact('categories', 'companies'));
}
I have two select inputs: the first one is a company list and second is a category which depends on company select because every company has a different category.
Ajax Request
$(document).ready(function () {
$("#company").change(function () {
var select = $('#company').find(":selected").val();
$.ajax({
url: "{{ route('product.create') }}",
method: 'PUT',
dataType: 'text',
data: {
keyname: select,
_token: '{{csrf_token()}}'
}, success: function (response) {
console.log(select);
}
});
});
});
However, $request->get('keyname')
isn't getting the select
value.