I am trying to get JSON data from API on Laravel 5 , The route gives me correct Data in the browser but when trying to access this route in JQuery it failed. the route is: http://localhost:8000/search/student/all
worked finally in the browser and the data is displayed in json format but this script failed:
 $(document).ready(function(){
     $("button").click(function(){
        $.getJSON("http://localhost:8000/search/student/all", function(result){
            $.each(result, function(i, field){
                $("div").append(field + " ");
            });
        });
    });
});
I replaced localhost:8000 with 127.0.0.1:8000 but nothing changed.
Note: I generated the json response using Laravel
$students=App\Student::all();
return response()->json($students);
 
     
     
     
    