mardi 12 mai 2020

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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire