jQuery的阿贾克斯返回404错误,但正确的反应 [英] jQuery Ajax returning 404 Error, but correct Response
问题描述
我通过jQuery AJAX张贴一些数据到PHP脚本,一切都正确执行,但它返回一个404错误。在我的Firebug的控制台从PHP脚本中的反应是正确的。我不知道如何脚本可以响应,并且它仍然抛出一个404错误。 jQuery的错误回调方法触发,而成功的方法不。
由PHP脚本执行的工作准确,因为我能看到的数据库更新,等等。所有的语句
我使用jQuery 1.4.2,由Dreamhost的托管一个字preSS 3.x的网站。
-----------更多信息-----------
好了,我已经想通了,当我有字preSS的 WP-博客 - 的header.php在阿贾克斯脚本
文件,我得到的错误。而且,曾几何时,这些脚本的工作,而我90%确信他们停止了WP 3.0更新后的工作。我将粘贴从Firebug的响应头。
从PHP,包括可湿性粉剂博客 - header.php文件,在Firebug返回404错误这头回应...
日期星期二,2010 1时44分44秒格林尼治标准时间8月10日
服务器阿帕奇
的X技术,通过PHP / 5.2.6
的X pingback的http://www.learnwake.com/xmlrpc.php
周三到期,1984 05:00:00 GMT 1月11日
缓存控制无缓存,必须-重新验证,最大年龄= 0
语用无缓存
上次修改星期二,2010一点44分44秒格林尼治标准时间8月10日
具体费用接受编码
内容编码的gzip
内容长度36
保持活动超时= 2,上限= 98
连接保持
内容类型text / html;字符集= UTF-8
这从PHP头响应不包括可湿性粉剂博客 - header.php文件,并返回一个200萤火虫OK ......
日期星期二,2010 1点44分58秒格林尼治标准时间8月10日
服务器阿帕奇
的X技术,通过PHP / 5.2.6
具体费用接受编码
内容编码的gzip
内容长度36
保持活动超时= 2,最大值= 100
连接保持
内容类型text / html
在包括 WP-博客 - 的header.php
,你最终自举整个单词preSS安装例程。函数 WP()
被调用,它调用 $ WP->的main()
,这反过来又要求不同设置功能。</ P>
其中之一就是 $ WP-&GT; query_posts()
,要求 $ wp_the_query-&GT;查询()
,这反过来又要求 WP_Query
的 parse_query()
功能。我的犯罪嫌疑人的,在那里产生了404指示(你的AJAX页面不是WP后,或类似的东西),并通过 $ WP-&GT; handle_404()
,在 query_posts()
在的main()
。
我不是100%肯定 parse_query()
是明确的罪魁祸首,但我会建议您查看一下,如果你可以只包括 WP- load.php
而不是,因为我认为它确实创造,你要访问的对象的实际工作。
此外,我实际上并不使用Word preSS,所以我不能肯定,但查看源$ C $ C这似乎是最有可能的情况下,从我可以告诉。
I'm posting some data to a PHP script via jQuery AJAX, and everything executes correctly, but it returns a 404 error. In my Firebug console the response from the PHP script is correct. I don't understand how the script can respond, and it is still throwing a 404 error. The jQuery "error" callback method triggers, and the "success" method doesn't.
All statements performed by the PHP script work accurately, because I can see the database being updated, etc.
I'm using jQuery 1.4.2, on a WordPress 3.x website hosted by Dreamhost.
-----------MORE INFO-----------
OK, I've figured out that when I include WordPress's wp-blog-header.php
file in the Ajax script, I get the error. Also, once upon a time these scripts work, and I am 90% sure they stopped working after the WP 3.0 update. I'll paste in the Response headers from Firebug.
This header response from PHP that includes the wp-blog-header.php and returns a 404 error in Firebug...
Date Tue, 10 Aug 2010 01:44:44 GMT
Server Apache
X-Powered-By PHP/5.2.6
X-Pingback http://www.learnwake.com/xmlrpc.php
Expires Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control no-cache, must-revalidate, max-age=0
Pragma no-cache
Last-Modified Tue, 10 Aug 2010 01:44:44 GMT
Vary Accept-Encoding
Content-Encoding gzip
Content-Length 36
Keep-Alive timeout=2, max=98
Connection Keep-Alive
Content-Type text/html; charset=UTF-8
This header response from PHP that doesn't include the wp-blog-header.php and returns a 200 OK in Firebug...
Date Tue, 10 Aug 2010 01:44:58 GMT
Server Apache
X-Powered-By PHP/5.2.6
Vary Accept-Encoding
Content-Encoding gzip
Content-Length 36
Keep-Alive timeout=2, max=100
Connection Keep-Alive
Content-Type text/html
When you include wp-blog-header.php
, you end up bootstrapping the whole WordPress setup routine. The function wp()
is called, which calls $wp->main()
, which in turn calls various setup functions.
One of these is $wp->query_posts()
, which calls $wp_the_query->query()
, which in turn calls WP_Query
's parse_query()
function. I suspect that the 404 indication is generated in there (your AJAX page isn't a WP post, or anything like that), and is later transformed into an actual 404 response header by $wp->handle_404()
, the function called after query_posts()
in main()
.
I'm not 100% sure that parse_query()
is the definite culprit, but I would suggest seeing if you can just include wp-load.php
instead, since I believe it does the actual work of creating the objects that you want to access.
Again, I don't actually use WordPress, so I can't be sure, but looking at the source code this seems to be the most likely case, from what I can tell.
这篇关于jQuery的阿贾克斯返回404错误,但正确的反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!