No initial data on load from server
No initial data on load from server
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
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
Thanks for your reply, I'll find a way to show you an example, because the problem may be on the server side.
Do you have
deferLoading
enabled withserverSide
? This will stop the first ajax request.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
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.
@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.
@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 .