【问题标题】:$.getJSON works on localhost but not on remote server$.getJSON 适用于本地主机但不适用于远程服务器
【发布时间】:2019-09-27 22:56:41
【问题描述】:

当我在安装了 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 不能在我的远程服务器上工作?

【问题讨论】:

  • 您是否在 Apache 中正确设置了站点的根目录?如果你去https://yoursite.com/ 会打开你的 index.html 文件吗?通常看起来像DocumentRoot /var/www/yoursite/htdocs

标签: javascript jquery json azure getjson


【解决方案1】:

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

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

            ServerAdmin admin@yoursite.com
            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。希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2011-02-03
    • 2012-09-23
    • 2014-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多