No initial data on load from server

No initial data on load from server

hellsinghellsing Posts: 22Questions: 8Answers: 0

Hey Guys,

Could somebody tell me how to make an initial ajax request when initialising DataTables?

When I load my page I get an empty table, the 3-dot 'Loading' icon and an error message on the console: 'jQuery.Deferred exception: n is null' (I guess it's because the table is empty). No ajax request is sent to the server at initialisation. DT fills up my table as soon as I click on any column header to order data or make any search so the connection and server-side php are OK.

I could send data from php to the client when the user loads the page but in my opinion, it would overwrite the functionality of stateSave as the server has no idea what was the last 'state' the user had.

What is the solution? Thanks!

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Could somebody tell me how to make an initial ajax request when initialising DataTables?

    Using the ajax option should be enough. See this example.

    If you are getting an error, can you link to the page with the issue so I can take a look into it please.

    Allan

  • hellsinghellsing Posts: 22Questions: 8Answers: 0

    Thanks for your reply, I'll find a way to show you an example, because the problem may be on the server side.

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    edited January 13

    Do you have deferLoading enabled with serverSide? This will stop the first ajax request.

    jQuery.Deferred exception: n is null'

    I would follow the traceback to see where the error is coming from. It might not be Datatables related nor related to not firing the initial ajax request. for testing purposes you may need to use the non-minified version of the library generating the error to see the code its coming from.

    As Allan said a link to a page showing the error will be useful for us to help debug.

    Kevin

  • mightydronmightydron Posts: 3Questions: 0Answers: 0

    Ensure you have the 'ajax' property configured correctly with the URL pointing to your server-side script. Also, the 'n is null' error might be due to some DOM element not being found. Double-check your HTML structure and make sure your table has the correct ID or class. As for state Save, you're right about not overwriting it.

  • hellsinghellsing Posts: 22Questions: 8Answers: 0

    @mightydron: I guess the ajax was set properly because after any activity on the table (search, ordering, paging) the data arrived. The problem was in my overcomplicated php server side script. I made a step back and voilà, my data came back.

    Thanks to everyone for your help, it was my fault.

  • mightydronmightydron Posts: 3Questions: 0Answers: 0

    @mightydron:You could send initial data from PHP only if the request is not an Ajax request, preserving the DataTables state. As for IP proxy servers, I would recommend http://pyproxy.com/?utm-source=crd&utm-keyword=?s1111. They can affect the performance of your application .

Sign In or Register to comment.