views:

37

answers:

2

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?

+1  A: 

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.

Māris Kiseļovs
Thanks for the tip. I found something interesting in the error log (see update). It looks like Apache is the cause of the problem - incorrect routing or something. Any ideas to what that might be?
Steven
@Steven I got only one idea about how to get such error - maybe you requested I:/Development... directly at some point, so jQuery tried to get mysite.com/wp-content/plugins/i:/development... . Can you try to change third line in your JS example to jQuery.post("/wp-content... ?
Māris Kiseļovs
Nope, didn't work. But I have narrowed down my problem. See update.
Steven
A: 

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

Jhong
in my PHP file, before `<?php php>`, I have written TEST - and tha's outputted when I open my file using the same url.
Steven
How do you mean "open with the same url"? Obviously you can't load a file in a browser address bar with a relative URL, so it must be different from your code sample. What are the absolute URLs?
Jhong
I'm also not sure what relevance the DNS and apache config have in this case. If you can load the page with the JavaScript, then clearly your site is already set up. have you tried changing `../wp-content/plugins/wp-eventcal/myfile.php` to `wp-content/plugins/wp-eventcal/myfile.php`?
Jhong
jQuery fails to open this URL: `http://mysite.com/wp-content/plugins/wp-myplugin/myfile.php`. If I paste the very same URL directly into my browser, I'm able to open my file. However, looking at my Apache error log, I doscovered something interesting (see update)
Steven
The `..` only takes me outside the wp-admin folder. If I don't add `..`, it will try to look for the file inside the wp-admin folder.
Steven
This is a plugin by the way
Steven
Oh, I see, it's being run from wp-admin. Do you have permalinks turned on, or has WP created a .htaccess?
Jhong
Yes and yes. I'm backend in admin when I get this message. I use permalinks and WP has createds .htaccess file.But this is jQuery/apache problem - not being able to get correct path. I think..
Steven
Try changing `I:\Development\wamp\www\mysite1` to `"I:/Development/wamp/www/mysite"`.
Jhong
Tried that, didn't have any effect. Take a look at my update. It has something to do with Permalinks and .htaccess file.
Steven