无法使用 jQuery.post 找到文件
我现在已经在几个 jQuery 脚本中使用了 jQuery.post,并且一切正常。但升级到 WordPress 3.0 后,它就停止工作了。
我正在开发一个插件,其中有以下 jQuery 代码:
//Delete event and remove from UI
jQuery("#eventList .cancelEvent").live('click', function() {
jQuery.post("/wp-content/plugins/wp-eventcal/myfile.php", { instance: 'cancelEvent' },
function(data)
{
alert('test'); // Never fires because 404 File Not Found
});
});
Firebug 报告“404 文件未找到”错误。这是链接: http://mysite.com/wp-content/plugins/wp- myplugin/myfile.php
如果我复制链接并将其粘贴到浏览器中,则页面可以正常打开。没有“404 文件未找到”错误。
查看我的 Apache 错误日志,我看到以下错误:
Cannot map GET
/wp-content/plugins/I:/Development/wamp/www/norwegianfashion/wp-content/themes/norwegianfashion/images/icon.png HTTP/1.1 to file,
referer: http://norwegianfashion.com/wp-admin/admin.php?page=wp-eventcal/eventcal-manager.php
这是我的 Apache 配置:
LoadModule rewrite_module modules/mod_rewrite.so
NameVirtualHost localhost
<VirtualHost localhost>
ServerName localhost
DocumentRoot "I:/Development/wamp/www/"
</VirtualHost>
<VirtualHost localhost>
ServerName mysite.com
DocumentRoot I:\Development\wamp\www\mysite
</VirtualHost>
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
这是我的 .htaccess 文件:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
更新
好的,我已将范围缩小到此。
仅当我使用 /%category%/%postname% 打开自定义永久链接时才会出现问题。
如果我使用默认的永久链接,一切正常。
那么,这可能是我的 .htaccess 文件吗?
I've used jQuery.post in several jQuery scripts now, and it all works fine. But after upgrading to WordPress 3.0, it stoped working.
I'm working on a plugin where I hve the following jQuery code:
//Delete event and remove from UI
jQuery("#eventList .cancelEvent").live('click', function() {
jQuery.post("/wp-content/plugins/wp-eventcal/myfile.php", { instance: 'cancelEvent' },
function(data)
{
alert('test'); // Never fires because 404 File Not Found
});
});
Firebug reports a '404 File not found' error. This is the link:
http://mysite.com/wp-content/plugins/wp-myplugin/myfile.php
If I copy the link and paste it into my browser, the page opens just fine. No '404 File not found' error.
Looking at my Apache error log, I see the following error:
Cannot map GET
/wp-content/plugins/I:/Development/wamp/www/norwegianfashion/wp-content/themes/norwegianfashion/images/icon.png HTTP/1.1 to file,
referer: http://norwegianfashion.com/wp-admin/admin.php?page=wp-eventcal/eventcal-manager.php
This is my Apache config:
LoadModule rewrite_module modules/mod_rewrite.so
NameVirtualHost localhost
<VirtualHost localhost>
ServerName localhost
DocumentRoot "I:/Development/wamp/www/"
</VirtualHost>
<VirtualHost localhost>
ServerName mysite.com
DocumentRoot I:\Development\wamp\www\mysite
</VirtualHost>
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
And this is my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
UPDATE
Ok, I have narrowed it down to this.
I only get the problem when I turn on custom Permalink using /%category%/%postname%.
If I use default permalink, all works fine.
So again, could it be my .htaccess file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需检查 Apache 的错误日志,您就会看到真实的请求路径以及拒绝的原因。很可能您因 myfile.php 的相对路径而失败,或者 wordpress 阻止了它。
您还可以尝试在 JS 代码中设置 myfile.php 的完整路径。
Just check Apache's error log and you will see real request path and why it's denied. Most likely you failed with relative path to myfile.php or wordpress is blocking it.
You can also try to set full path to myfile.php in your JS code.
您确定网址正确吗?它是相对于HTML页面而言的,wordpress的index.php通常与wp-content目录处于同一级别。因此我倾向于怀疑 URL 应该是 'wp-content/plugins/wp-eventcal/myfile.php' ?
You sure the URL is correct? It is relative to the HTML page, and wordpress' index.php is normally at the same level as the wp-content directory. I'd be inclined to suspect therefore that the URL should be 'wp-content/plugins/wp-eventcal/myfile.php' ?