DataTables 3.0.2 Lost XmlHttpRequest Headers
DataTables 3.0.2 Lost XmlHttpRequest Headers
Link to test case:
https://live.datatables.net/leduturi/2/
Error messages shown:
Popup message pointing to https://datatables.net/tn/7
Description of problem:
My ajax data sources stopped working when I attempted to upgrade from v2.3.5 to v3.0.2. I was able to identify two issues:
Issue 1 - Error Message
The error message is inaccurate because of a typo. Referencing the cdn source:
Line 610: statusText = 'parseerror';
vs
Line 7592: if (error == 'parsererror') {
This leads you to a message about response codes, when in reality the server is sending back a 200 response, but it's unable to be parsed by DataTables.
Issue 2 - Accept Header
It looks like XmlHttpRequests were migrated from delegating to jQuery to a making direct call. This has the side effect of losing the HTTP headers that were previously set, except for 'X-Requested-With'.
In particular, we lose the accept header that specifies the json format. This is needed when pointing to our Spring endpoint, which otherwise sends back XML as a default.
In 2.3.5, the header is set to application/json, text/javascript, */*; q=0.01.
In 3.0.2, it's just */*, which you can see in the example link.
I confirmed that adding a custom accept via ajax.headers resolves this issue, but I'm unclear whether other headers would need to be properly updated as well.
Let me know if this all sounds plausible, or if there could be an issue with the implementation.
Answers
Hi,
Many thanks for flagging these up!
1) That's a frustrating error - sorry about that. Fixed here.
2) I don't intend to match jQuery exactly, that would be pointless, instead focusing on parts that make sense for DataTables, and I would agree that in this case, a chance to match the behaviour there does make sense. When
dataType: 'json'is specified, theAcceptheader should be weighted for JSON data. I've added a commit to implement that.DataTables 3.0.3 isn't far away (maybe this afternoon in fact), and these two changes will be included in it.
Many thanks again,
Allan
Thank you, Allan! I'll give 3.0.3 a go when I get a chance.