0

My controller:

 function index()
{
    return view('student.ajaxdata');
}

function getdata()
{
    $student = Student::select('first_name', 'last_name', 'Age', 'Address', 'Grade_Level');
    return Datatables::of($student)->make(true);
}

jQuery code:

$(document).ready(function() {
    $('$students_table').Datatables({
        "processing" : true;
        "serverside" : true;
        "ajax" : "{{route('ajaxdata.getdata')}}"
        "column":[
            {"data" : "first_name"},
            {"data" : "last_name"},
            {"data" : "Age"},
            {"data" : "Address"},
            {"data" : "Grade_Level"}
        ]
    });
})

It supposed to fetch data and put in the table but in my case there's no error or anything but when i go to the view page there's no data was fetch.

3
  • What is the $students_table in $('$students_table'). Is this a HTML selector? And one more thing you should post the question with code not the pictures that include the code!!! Commented Jul 26, 2018 at 2:11
  • Pro-tips: (1) when labelling code, it is clearer if the label comes before the code, using a : colon to indicate the material is following. I have seen people put the label at the end (in a sort of "see above" way) but it is rarely used, since people usually scan the page from top to bottom. (2) when asking questions, try to refrain from chatty material and pleading. Don't add crying eyes emoticons to show how sad you are, as some readers don't like begging and pleading - they may instead downvote and move on. This discussion may be useful. Commented Jul 26, 2018 at 6:50
  • What does "not working" mean - would you edit the question to clarify this? Commented Jul 26, 2018 at 6:59

2 Answers 2

1

The issue is your JS part.

$('$students_table')

It should be $('#students_table') with a hash.

Sign up to request clarification or add additional context in comments.

Comments

0

Verify if Datatables::of($student)->make(true) returns a Json array.

Like this:

dd(Datatables::of($student)->make(true));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.