$。getJSON在本地主机上有效,但在远程服务器上不可用

问题描述 投票:0回答:1

当我在安装了Apache的Arch Linux机器上转到localhost时,以下代码成功加载了JSON文件。

$.getJSON("geo/my.json",function(jsonStuff){
  // Code here
})

但是当我导航到由Microsoft Azure驱动的服务器时,我的Web浏览器的控制台将显示此消息。

GET https://path/to/my.json 404 (Not Found)

我知道文件和文件夹在那里,因为我通过FileZilla将它们传输到了远程服务器。当我使用FileZilla打开包含my.json的文件夹时,在那里看到了文件。

根目录看起来像这样。

index.html
geo
  my.json
js
  script.js

当我将浏览器导航到https://path/to/my.json时,会看到此消息。

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

为什么$.getJSON无法在我的远程服务器上工作?

javascript jquery json azure getjson
1个回答
0
投票

确保在网站的Apache配置中正确设置了文档根目录。

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>

            ServerAdmin [email protected]
            ServerName yoursite.com
            ServerAlias www.yoursite.com
            DocumentRoot /path/to/your/website/directory     <-Make sure this is correct.
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
            SSLEngine on

    </VirtualHost>
</IfModule>

如果my.json文件位于/var/www/mysite/geo/my.json,则您的DocumentRoot应该为DocumentRoot /var/www/mysite。希望有帮助。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.