When AJAX is calling my laravel method, the method is called, but the var for the search term is null (Using Select2 for my combobox). However, the same code runs fine on my local dev machine.
I've updated laravel to 5.8.11 to see if that would help as my local machine was running a slightly newer build, php, reviewed logs, chrome inspector, nothing shows any errors for this.
public function get_codes(Request $request)
{
$search = trim($request->q);
if(empty($search))
{
return response()->json([]);
}
$data = [];
$data = DB::table("codes")
->select("id","dx_code", "description")
->where('dx_code','LIKE',"$search%")
->get();
return response()->json($data);
}
ajax: {
url: "/dxcodes",
dataType: "json",
delay: 250,
data: function (params) {
return {
q: $.trim(params.term)
};
},
processResults: function (data) {
return {
results: data
};
},
cache: true
}
my json response is: [] (after running tests, I found my $request->q is treated as empty) however, if I remove the if(empty), I get my response. I don't understand it... again, please remember, all this works perfectly on my local machine. I have other ajax calls in my app on the production server and they work fine, it's just this one call.
The fix for this issue was the nginx web server config file for this site was not set correctly. Nginx doesn't use .htaccess files. The ? was missing after index.php
try_files $uri $uri/ /index.php$query_string; (BAD)
try_files $uri $uri/ /index.php?$query_string; (GOOD)