php - jQuery - 获取 News.html 404(未找到)

标签 php ajax jquery

由于某种原因,这不起作用:

$.ajax({
    url: "News.html",
    cache: false,
}).done(function(data) {
    $("#content").load(data);
});

它给了我:

GET http://127.0.0.1/News.html 404 (Not Found)

但无论出于何种原因,手动打开该网址(复制粘贴网址)就可以了。 我一开始认为这与浏览器缓存有关,所以我在 ajax 函数中添加了 cache: false 选项,但即便如此.. argh..

此外,它在我的 access.log 文件中显示为请求的 URL。

对于我猜的信息,我正在运行:

  • lighthttpd
  • php 通过 localhost:port 作为 fast-cgi
  • 映射的 .html => .php
  • 运行 OpenBSD 5.3

并且取消注释(在/etc/php.ini中):

  • cgi.fix_pathinfo=1

另外:

# ls *.html
News.html     index.html

这是 News.html 的请求 header :

Request URL:http://127.0.0.1/News.html
Request Method:GET
Status Code:404 Not Found

请求 header

Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Host:127.0.0.1
Referer:http://127.0.0.1/index.php
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36
X-Requested-With:XMLHttpRequest

响应 header

Content-type:text/html
Date:Tue, 16 Jul 2013 21:55:05 GMT
Server:lighttpd/1.4.32
Transfer-Encoding:chunked
X-Powered-By:PHP/5.3.21

检查点

到目前为止的评论得出的结论是,这可能根本不是 jQuery 问题。 考虑到服务器响应所有数据(我已检查发送的原始数据)并且它包含所有内容,但响应 header 显示404

意思是,找到了数据,但 header 显示 404...至少可以说很奇怪......

curl 测试

curl 'http://127.0.0.1/News.html' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Host: 127.0.0.1' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36' -H 'Accept: */*' -H 'Referer: http://127.0.0.1/' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --compressed
Here you'll soon find a facebook feed, among other things :)

Zerkms 测试

# echo "wham bam" > zerkms_doesnt_believe.html
# 

enter image description here

配置文件

错误日志以及其他日志

cURL 测试

A cURL copy paste test

通过 Python 客户端进行手动 FastCGI 测试:

# python fcgi_app.py  
{'FCGI_MAX_CONNS': '1', 'FCGI_MPXS_CONNS': '0', 'FCGI_MAX_REQS': '1'}

经过一番修改,我弄清楚了 FastCGI 协议(protocol)是如何工作的,并且找到了一个符合我需求的客户端,有趣的是它与我的脚本名称相匹配,所以这是输出:

# python fcgi_app.py  
('404 Not Found', [('x-powered-by', 'PHP/5.3.21'), ('content-type', 'text/html')], '<html>\n\t<head>\n\t\t<title>test php</title>\n\t</head>\n<body>\nChecking</body>\n</html>', '')

Here's the source

给我的结论是,这实际上是一个 PHP 问题(尽管我讨厌 lighttpd,因为它不遵守 php 应该响应的 200 代码。对此我很抱歉。应该稍微抨击一下PHP,看看这是否有助于我得出结论)

临时解决方案

将以下内容放在 .php 页面的顶部可以解决此问题。 请注意,这是一个干净的解决方法,它会起作用,但肯定不是一个长期解决方案。

<?php
    header("HTTP/1.0 200 Found");
?>

最佳答案

这有点像同源策略问题。 您指定的路径可能会导致问题。 尝试一下

$.ajax({
    url: "/News.html",
    cache: false,
}).done(function(data) {
    $("#content").load(data);
});

请告诉我(我们)这是否有帮助。

关于php - jQuery - 获取 News.html 404(未找到),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17687671/

相关文章:

php - 获取带空格的变量 - 它们可以工作,但它是否正确或可以?

jQuery 获取属性

php - 如何创建 "Next Page"链接到 mySQL 搜索的 "non-displayed"结果?

javascript - 知道如何禁用嵌入式 "Vine.co"视频的自动播放吗?

javascript - 当 body 背景图像完成加载时显示警报

jquery - panopticlick 如何检测浏览器中可用的字体?

javascript - 使用 javascript/jquery 从表格的给定行中提取 Cell/Td/tabledata 值

php - 路由到 Laravel 5 子文件夹中的 Controller

php - 如何在mysql查询中获得排序结果?

php 以两种方式对数组进行排序