Bug: Language file not loaded (NetworkError: 405 Method Not Allowed) when type: post on $.ajaxSetup
Bug: Language file not loaded (NetworkError: 405 Method Not Allowed) when type: post on $.ajaxSetup

DataTables now (1.10) uses the $.ajax
method to get the language definitions from a file, instead of $.getJSON
used on previous versions (1.9).
If the developer sets type to POST as a default for jQuery AJAX calls via $.ajaxSetup
, then the request to the language file will also be a POST. If the file is a TXT, we get NetworkError: 405 Method Not Allowed
.
The fix is easy, just add the type
to the AJAX call (line 6289):
$.ajax( {
dataType: 'json',
type: 'GET', // <-- here
url: oLanguage.sUrl,
Code to replicate the error:
<html>
<head>
<script src="jquery-1.11.1.min.js"></script>
<script src="DataTables-1.10.4/media/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function() {
$.ajaxSetup({
type: "POST"
});
$('#mytable').dataTable( {
"language": {
"url": "dataTables.portugues.txt"
}
});
});
</script>
</head>
<body>
<table id="mytable"><thead><tr><th>col1</th></tr></thead><tbody></tbody></table>
</body>
</html>
This discussion has been closed.
Replies
Perhaps its a good idea to also include other options that might be set by the developer and could change the expected DataTables behavior, such as
async: true
.Thanks for noting this. Setting Ajax options for the language configuration is a good idea and something I will look into.
Allan