通过 jquery 加载名称中带有变音符号的文件

Load a file with an umlaut in its name via jquery

我需要通过 jquery 加载请求获取文件名中包含变音符号的文件的内容。我知道根本不推荐在文件名中使用变音符号。

奇怪的是,我在不同的项目中使用完全相同的代码和相同版本的 jquery,并且在那里工作得很好。

<a class="nav-link d-inline pl-1 pr-3" href="#" data-path="Ränge">

<script>
$(document).ready(function(){
            $(document).on('click','.nav-link, .internalLink', function(event){
                event.preventDefault();
                console.log('prevented default');
            });


            function loadContent(path, forward) {
                console.log(path);
                path = path.toLowerCase().replace(/^[\u00C0-\u1FFF\u2C00-\uD7FF\w]|\s[\u00C0-\u1FFF\u2C00-\uD7FF\w]/g, function(letter) {
                        return letter.toUpperCase();
                    });
                console.log("tried to load: " + path);
                $('#content').hide('drop', function(){
                    $('#content').load('content/' + path + '.html', function(response, status, xhr){
                        if(status == 'error'){
                            if(xhr.status == '404'){
                                $('#content').load('content/404.html');
                            }
                            else {
                                $('#content').html('Es ist ein Fehler aufgetreten: ' + xhr.status + ' ' + xhr.statusText);
                            }
                        }
                        if(path == 'Startseite' || forward == false){
                            window.history.replaceState('MyWebsite | ' + path, path, '/' + path);
                        }
                        else {
                            window.history.pushState('MyWebsite | ' + path, path, '/' + path);
                        }
                        document.title = 'MyWebsite | ' + decodeURI(path);
                        $('#content').show('drop');                    
                    });
                });
            }

            var path = window.location.pathname == '/' ? 'Startseite' : window.location.pathname;
            path = path.replace('/', '');
            loadContent(path, true);

            window.onpopstate = function() {
                path = window.location.pathname;
                path = path.replace('/', '');
                loadContent(path, false);
            };

            $(document).on('click', '.nav-link, .internalLink', function(){
                path = $(this).attr('data-path');
                if(path == 'MusicBot'){
                    window.open('https://MyMusicBotWebsite.de');
                }
                else {
                    if(decodeURI(window.location.pathname.replace('/', '')) != path){
                        loadContent(path, true);
                    } 
                }
            });
        }); 
</script>

consol 输出显示路径应该是“Ränge”,但我收到 404 错误,因为 ajax 请求试图加载 https://MyWebsite.de/content/R%C3%A4nge.html and it should load https://MyWebsite.de/content/Ränge.html

提前致谢

这是一个与 Plesk 相关的问题...

我真傻,我使用了 Plesk 网络界面的 zip 上传功能,文件显示为 Ränge.html

所以今天我查看了使用相同加载脚本的两个网站的http日志。 Plesk 说找不到 Ränge.html,因为该文件不存在,但在其他网站上可以找到。我打开了 Filezilla 并通过 FTP 查看了文件并看到了这个:Rдnge.html

所以 Pleks 在 webinterface/filemanager 中显示了正确的文件名,但磁盘上的文件名不正确。

所以这个问题的解决方案是通过 FTP 而不是通过 Plesk web 界面上传文件。