无法使用jQuery.post查找文件

时间:2010-08-01 12:19:50

标签: jquery wordpress wordpress-plugin 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 File not found'错误。

查看我的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文件吗?

2 个答案:

答案 0 :(得分:1)

只需检查Apache的错误日志,您将看到真实的请求路径以及拒绝的原因。很可能你用myfile.php的相对路径失败了,或者wordpress阻止了它。

您还可以尝试在JS代码中设置myfile.php的完整路径。

答案 1 :(得分:0)

您确定网址是否正确?它与HTML页面相关,wordpress'index.php通常与wp-content目录处于同一级别。我倾向于怀疑URL应该是'wp-content / plugins / wp-eventcal / myfile.php'?