【发布时间】:2013-03-19 05:58:54
【问题描述】:
我真的不明白。我有以下“获取”请求:
$.ajax( {
url: "api/getdirectories/",
dataType: 'json',
success: function ( data ) {
// Do stuff
}
} );
这是由我的登台服务器 http://atlas/Reporter 提供给我的页面中的。在我的本地开发盒上,这是可行的,并且在查看提琴手时,我看到了正确的 URL http://localhost/Reporter/api/getdirectories。然而,在暂存服务器上,请求是到 http://atlas/api/getdirectories,这是无效的,我收到 404 错误。
为什么我的路径中的“报告者”部分被丢弃在登台服务器上?看文档,URL、baseURI、documentURI都是http://atlas/Reporter,域是atlas。和我的本地开发盒完全一样(除了都是 'localhost' 而不是 'atlas'。
这个问题困扰了我一段时间。我想我已经弄清楚了,一切都很好,然后我又遇到了。我认为这不是同源策略问题,因为我从页面来源的同一站点请求数据。
那么,请求的完整 url 究竟是如何确定的呢?它似乎不是上面提到的文档变量之一,它被连接到我的相对 URL 上……那么它是如何工作的?
Edit: Removed the '/' from the URL as it is distracting from the real issue- behavior is the same with or without it.
【问题讨论】:
-
你的网址不应该是
api/getdirectories/而不是/api/getdirectories/吗? -
你试过 url:"api/getdirectories/",
-
我试过
api/getdirectories,效果一样。 -
您的 HTML 文件的路径是什么,您在浏览器中使用什么 URL 来打开它?
-
@dystroy 正确的路径是
http://atlas/reporter/api/getdirectores。这是托管在我的服务器上的 web.api 应用程序。
标签: jquery ajax xmlhttprequest