我很难让我的 AJAX 请求在临时服务器上工作。在我的开发机器上一切正常,但是一旦我上传它,我所有的 AJAX 请求就停止工作了。我发现,如果我将相对 URL(例如“index.php”)更改为绝对 URL(“http://example.com/index.php”),请求将再次起作用,但我不明白为什么。
示例请求:
jQuery.post('index.php', {id: 1234, action: 1, step: 1}, function(data) { /* something */ });
这不起作用,我什至没有出现在 Firebug 控制台中。虽然调用了成功处理程序,这非常令人困惑。
这很好用:
jQuery.post('http://example.com/index.php', {id: 1234, action: 1, step: 1}, function(data) { /* something */ });
谁能解释为什么 AJAX 请求会以这种方式运行? x_X
最佳答案
尝试在您的第一个示例中的 index.php
之前添加一个 /
以强制它从根目录查找。仔细检查以确保您的目录结构与 index.php
的位置完全相同相同。
关于php - jQuery AJAX 请求中的相对与绝对 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2363511/