开发者

Not able to find file using jQuery.post

开发者 https://www.devze.com 2023-01-09 23:22 出处:网络
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'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 whe开发者_如何学JAVAre 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?


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.


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' ?

0

精彩评论

暂无评论...
验证码 换一张
取 消