尽管有正确的查询字符串参数,但Ajax GET请求为空

Using a simple Ajax GET request to retrieve some data, it successfully checks if($request->ajax()) {} but then fails any validation because there is no data in the Request $request variable. This happens only on the production server, on localhost everything works fine.

The console shows the intended URL https://example.com/employeeInfo?id=1, then error 422 (Unprocessable Entity). Output from error: function(jqxhr, status, exception) { alert('Exception:', exception); } gives an empty alert message.

View

<script>
(function ($) {
$(document).ready(function() {
    $(".team-pic").off("click").on("click", function() {
         $id = $(this).data('id');

         // Get data
         $.ajax({
            type: 'GET',
            url: 'employeeInfo',
            data: {'id':$id},
            success: function(data){
                var obj=$.parseJSON(data);
                // Show output...
            },

             error: function(jqxhr, status, exception) {
                alert('Exception:', exception);
            }
        });

      });
});
}(jQuery));
</script>

Route

Route::get('/employeeInfo', 'EmployeeController@get');

Controller

public function get(Request $request) {

    if($request->ajax()) {

        $this->validate($request, [
            'id' => 'required|integer',
        ]);

        // Id
        $employee = Employee::find(request('id'));

        // Create output
        $data = ...
        echo json_encode($data);

    }
}

If I were you, I would use a RESTful API with route model binding, specifically the explicit binding.

RouteServiceProvider.php

public function boot() 
{
    parent::boot();
    Route::model('employee', App\Employee::class);
}

Route

Route::get('api/employees/{employee}', 'EmployeeController@get');

Controller

public function get(Employee $employee)
{
    // The id being valid is already done by forcing it to be an Employee
    // It is also an ajax call because it is going to the api route
    // This will json_encode the employee object.
    return $employee;
}