简体   繁体   中英

Error 500 When return View from controller during ajax call

i have to create ajax call when user clicks on checkboxes to fetch the specific jobs according to each checkbox category. When in controller i return return \Response::json($jobs) The request works fine. But when im trying to return return View::make('jobs.alljobs')->with('jobs', $jobs); i got Error 500

JobController.php

$cat = Input::get('categories');
    $jobs = Job::whereIn('category_id',$cat)->get();
    return View::make('jobs.alljobs')->with('jobs', $jobs); 

AJAX Call function

function filterCategories(){

//Mark : Categories filters jquery
var categories = [];
// Listen for 'change' event
$('input[name="cat[]"]').on('change', function (e) {
  e.preventDefault();
  categories = []; // reset 
  $('input[name="cat[]"]:checked').each(function()
  {
      categories.push($(this).val());
  });
  console.log(categories);
  //Send request
$.ajax({
    url: '/jobs/searchcat',
    type: 'POST',
    data: {categories:categories},
    beforeSend: function (request) {
        return request.setRequestHeader('X-CSRF-Token', $("meta[name='csrf-token']").attr('content'));
    },
    success: function(response){
        console.log(response);
    }
})});}

Result when i return json

Error when i return view

Probably means that your script is throwing an uncaught error or exception when you return the view. Enable error logging and check your logs. Either of these pages might help with that.

https://laravel.com/docs/5.8/errors

https://laravel.com/docs/5.8/logging

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM