Start and Index not being read server side
Start and Index not being read server side
Hello,
First question here and recently started using DataTables.
I am having trouble with an ajax call to the server - I am getting the errors:
Notice: Undefined index: length in C:\xampp\htdocs\testing\fetch.php on line 37
Notice: Undefined index: start in C:\xampp\htdocs\testing\fetch.php on line 38
Notice: Undefined index: length in C:\xampp\htdocs\testing\fetch.php on line 38
I have provided a link to my github pages where the pertinent code resides:
https://github.com/ewanlp/BoardGameSite/blob/testing-luke/pages/players.php
https://github.com/ewanlp/BoardGameSite/blob/testing-luke/testing/fetch.php
Debugging has not shown me anything as far as I know, but here is link to that as well:
http://debug.datatables.net/uguzow
The page appears to work how it should - I am able to sort, order, and paginate successfully. This said, these notices are indicating that my query is not correct. This is because the length and start values are not being filled in my query. I find this odd because when I debug my code I get this:
Data source Server-side Ajax
Processing Server-side
Draws 1
Columns 3
Rows 10
Display start row 0
Display length 10
The values length and start are being returned with values to the server. I'm not sure if I'm interpreting this correctly, and if there is some clarification that anyone can provide, that would be much appreciated!
Thanks for any help.
Luke
Answers
Interesting.... Looking at the debugger output in the Table Tab go to "Initialization options" it looks like you have configured for an AJAX POST.
Under "Server interaction" it shows a "GET request:
Which would explain why you get those errors with this code:
What I don't understand is why it appears the request was a GET not a POST. Maybe Allan can explain?
Kevin
I fear that's a legacy bug in the debugger... (urgh). It does it on this example as well. I'll get that fixed.
Could you add
print_r( $_POST );
to the file at the very top (before the session start) and let me know what the server's response is (it will be invalid JSON, but that's not important).Allan
Thank you both for your responses.
When adding print_r($_POST); to the top of the fetch file, the server returns:
Array ()
When I preview the page in my Network tab, it returns:
Array( [draw] => 1 [columns] => Array ( [0] => Array ( [data] => 0 [name] => [searchable] => true [orderable] => true [search] => Array ( [value] => [regex] => false ) ) [1] => Array ( [data] => 1 [name] => [searchable] => true [orderable] => false [search] => Array ( [value] => [regex] => false ) ) [2] => Array ( [data] => 2 [name] => [searchable] => true [orderable] => false [search] => Array ( [value] => [regex] => false ) ) ) [start] => 0 [length] => 10 [search] => Array ( [value] => [regex] => false ))
Again, thank you for any help you can provide.
Luke
Hi Luke,
So that looks good -
start
andlength
are being submitted, and the server is seeing them.So next put that
print_r
line on line 29 and see if they are still there. If not, then one of the included scripts is mucking around with$_POST
.Allan
Allan,
Checked that out and it looks good there. I looked at all other included files and have posted links to them below. I'm not seeing anything that could be messing with POST but perhaps you might be able to spot it better.
When I use print_r right before line 39 I'm still seeing that start and length are being correctly filled with the appropriate values.
https://github.com/ewanlp/BoardGameSite/blob/testing-luke/ePHP/class.user.php
https://github.com/ewanlp/BoardGameSite/blob/testing-luke/ePHP/dbconfig.php
https://github.com/ewanlp/BoardGameSite/blob/testing-luke/testing/function.php
Let me know if there's any other links I can provide, or somewhere else the POST request might be interfered with.
Luke
This is weird. So if you have
print_r( $_POST )
on line 39-40 it shows thestart
andlength
parameters in it? But it is also showing the error message:?
I'm not sure I can explain that!
Allan
Hai there, I have the same problem. Any fix for this?
but when I echo $_POST I got this:
{"draw":null,"recordsTotal":2,"recordsFiltered":2,"data":[]}
and this is my ajax request:
```$(document).ready(function() {
table = $('#table').DataTable({
});```
and this is inside my network tab, form-data :