Problem with language.url
Problem with language.url
Error messages shown:
DataTables warning: table id=datenliste - i18n file loading error. For more information about this error, please see https://datatables.net/tn/21
Description of problem:
the script within the page:
new DataTable('#datenliste', { language: { search: 'In der Liste finden', url: 'styles/de-de.lang' },The file 'styles/de-de.lang' contains: ( from Internationalisation plug-in )
{
"emptyTable": "Keine Daten in der Tabelle vorhanden",
"info": "START bis END von TOTAL Einträgen",
..........
}
The chapter "21. i18n file loading error" doesn't give me a solution,
my browser Firefox (Version 133) and Edge (Version 131.0.2903) is CORS capable,
my IIS-7 has the entry "Access-Control-Allow-Origin *" under HTTP.
I get the same result if I rename the file to de-de .json
what can I do or what am I doing wrong?
This question has accepted answers - jump to:
Answers
Did you validate the JSON using JSON Lint as recommended in the technote?
Are you seeing the JSON response in the browser's network inspector?
What is the response status code?
Kevin
Yes .. i have validate with JSON Lint ( JSON is valid! )
I don't see the JSON response in the browser's network inspector.
It doesn't look like it is sending a request for the URL. Possibly you need to prefix the URL with a
/
, for example:As a test do you see the request if you use the CDN URL? For example:
Kevin
when i use //cdn.datatables.net/plug-ins/2.1.8/i18n/de-DE.json as test
in the Console you see
when i use styles/de-de.json :
when i use /styles/de-de.json:
when i use //styles/de-de.json:
You may need to add
https:
to the path so it fetches via the internet instead of a local resource:Does it work now?
Is the path correct?
If the CDN works with
https://....
and the local paths don't then you probably will need to look at your web server's config to determine the correct path.Kevin
url: 'https://cdn.datatables.net/plug-ins/2.1.8/i18n/de-DE.json' works fine.
What do you mean with "... web server's config ..."?
Which setting should I make? All websites are found.
The phyical Path on IIS is set on "C:\inetpub\wwwroot\iNetForum"
The structure:
a test00.html is my page and is physical in
"C:\inetpub\wwwroot\iNetForum"
the styles file is in the
"C:\inetpub\wwwroot\iNetForum\HTML\ STYLES" directory,
i think this is alright.
Sorry I gave incorrect answers.
Kevin
No problem ... but do you have an idea?
I don't know what to do anymore.
What files are in
styles
?The filenames are likely case sensitive.
Kevin
I'm not familiar with IIS so not sure how to debug the server to learn why its not responding with the JSON file.
Kevin
The files in directory are:
To see if its a permissions or IIS config issue move the JSON file to the same path as
test00.html
and removestyles
from thelanguage.url
option.Kevin
I think it has nothing to do with the IIS server.
url: 'https://cdn.datatables.net/plug-ins/2.1.8/i18n/de-DE.json' works.
Maybe it's because the language-option doesn't understand the URL-option with
url: 'styles/de-de.json' correctly?
What do you mean? Could this be?
My advice to further troubleshoot is to move the JSON file to a path you know works. The suggestion is that possibly there is a file permissions issue or that IIS is configured not to provide files from subdirectories.
EDIT:. I'm not saying it has to be permanent. Its just a test.
Kevin
Now i tried : url: 'de-de.json' - and move the file in the same directory
as the page is. - the same error message in browser console
... and the file is configured with full permissions for system, users, IIS-IUSRS ...
My next step would be to download the working CDN file (de-DE.json) and place it on the server. Either in the root or the styles directory. Does that work?
Kevin
Post your full JSON file so we can take a look.
Kevin
Ok .. i have downloaded the CDN File de-DE.json and take it in the HTML-directory where the testpage is (C:\inetpub\wwwroot\inetforum\html): - it doesn't work
the console:
When i take the file in the server-root ( C:\inetpub\wwwroot) or in the page-root (C:\inetpub\wwwroot\inetforum) - it doesn't work and the console shows
to be noted :
The Browser-console shows
file:///C:/inetpub/wwwroot/iNetForum/HTML/de-De.json
although the file does not exist in the HTML directory
the script is
new DataTable('#datenliste', { layout: { topStart: { buttons: ['searchPanes'] } }, language: { search: 'In der Liste finden', url: 'de-De.json' }, });Sorry I don't know anything about IIS. But this suggests to me a configuration issue with the IIS server. Maybe do some research on Stack Overflow for you particular IIS version and setup. Possibly Allan will have some ideas for you.
Do you see an XHR request in the browser's network inspector? If yes what is the status code response?
Kevin
No XHR request ...
I don't know of any way to configure the IIS server, eExcept the issue
I hope Alan has an idea
What is the diffrent between
url: '//cdn.datatables.net/plug-ins/2.1.8/i18n/de-DE.json' and
url: 'de-De.json'
When you added
https:
to the URL it worked. I wonder if your browser is not addinghttps:
. Try `url: 'https://de-De.json'. You may need to adjust the URL for it to work. Check for the XHR request.This is fetching from the datatables.net website - assuming
https:
is prefixed.This is attempting to fetch from the local web server.
Kevin
Ihave tried with https, the result a message from dataTables:
DataTables warning: table id=datenliste - i18n file loading error. For more information about this error, please see https://datatables.net/tn/21
and from the browser console:
from XHR:
I think it is a problem with CORS ( file-link in JS )
Starting a URL with
//
means it is "protocol relative". Whatever the host page is using, the Ajax URL will therefore also use.It sounds like you are loading your page directly from the file system, rather than going through a web-server (i.e. you are using
file://
). You can do that, but you cannot Ajax request other files from the hard drive. Doing so would be a massive security hole and browsers will disallow that. Which is what you are seeing.https://de-de.json
doesn't work, because there is no website at that address. It isn't looking up your hard drive, it is looking for a website of that address.If you must load your file from the local file system, and you must Ajax load the language configuration, then you must use an https:// URL that resolves, such as the one Kevin gave you before.
If you cannot use an external resource, but you must use
file://
to load the page, then you need to copy / paste the JSON for the language into your HTML file and uselanguage
to assign it to the DataTable.Allan
My guess was correct that it was a CORS problem and Allan is also right with his description.
The fact is that loading a local file with included local resources leads to CORS errors.
CORS requests can only use the HTTP or HTTPS URL scheme, but the URL specified by the request is of a different type. This often occurs when the URL specifies a local file with the file:/// scheme.
Especially Firefox and Edge are causing problems when CORS is not handled correctly. FF and Edge are considering requests to CDNs as "cross-domain" requests and won't load them unless it is explicitly stated in the HTTP header.
Developers who need to perform local testing should now set up a local server. Since all files are served from the same schema and domain (localhost), they all have the same origin and do not trigger cross-origin errors.
In my case : [ url: 'http://localhost/html/scripts/de-De.json']
For firefox you can use a special setting that prevents CORS:
about:config - „security.fileuri.strict_origin_policy“ set to „false“
No CORS error but in this case the console displays a XML error:
The safest solution: as Allan suggested
Instead of performing a cross-origin search for a resource, consider integrating it into the web app and use language Option. This completely avoids the cross-origin call (since it is now a local resource) and makes all CORS issues disappear.
Thank you for your support and I wish you a happy new year.