views:

91

answers:

1

ahoy,

i'm running wordpress 3x on nginx and all my ajax calls are broken. the exactly same wordpress runs fine on Apache.

i've fixed somehow an ajax call to work with nginx by removing 'index.php' from all jquery.post() calls, but i couldn't fix the other calls in the same way.

basically the changes were: for nginx the line:

jQuery.post( 'index.php?ajax=true', form_values, function(returned_data) {

was replaced with:

jQuery.post( '?ajax=true', form_values, function(returned_data) {

i suspect the problem lies in the nginx config file with rewrite rules. There you are with my configuration

if (!-e $request_filename) {
rewrite ^.+/?(/wp-.*) $1 last;
rewrite ^.+/?(/.*\.php)$ $1 last;
rewrite ^(.+)$ /index.php?q=$1 last;
}


location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /xxx/public$fastcgi_script_name;
include fastcgi_params;
}
}
A: 

Could it be that you are in a directory or "virtual" directory in the browser URL?

If, for example, you are at www.myblog.com this should work, but on www.myblog.com/my-category/my-post/ it probably wouldn't.

Have you done your testing from the exact same URL-location on the Apache site and the Nginx site?

Have you tried with a slash in front of the path to ensure that it is the root script being called?

jQuery.post( '/index.php?ajax=true', form_values, function(returned_data) {
Christoffer
"Have you done your testing from the exact same URL-location on the Apache site and the Nginx site?"Yes I've tested the exactly same application and urls. My URL is always something like www.blog.com/post-name.I did not tried with "/index.php?ajax=true" but with "?ajax=true" and worked in a case, not working in all other cases.
I recommend then, that you do try to put a leading slash before index.php since it will direct the action to the site's root index.php file. It should work, whether you are running Nginx or Apache.
Christoffer
Another tip is that you run the Ajax-script when using Firefox and have the Firebug console activated. You can then see that the Ajax-call is made and what result you are getting from it. You are most likely getting a 404 error.
Christoffer