AJAX Not Working For WP-Email, WP-Polls, WP-PostRatings or WP-PostViews?

About 2 weeks ago, I release an update to r WP-Email, WP-Polls, WP-PostRatings and WP-PostViews which added some nonce check and moved the AJAX request to be handled by /wp-admin/admin-ajax.php.

3 common issues that users are facing.

“-1” or “Failed To Verify Referrer”
This means that most likely you are using a caching plugin like W3 Total Cache (W3TC) and the Javascript being minified/combined and cached is outdated. Just empty the JS/CSS cache under the “Minify” section of W3TC in WP-Admin and W3TC will regenerate it again. This will solve the problem.

Password Protected /wp-admin/ Will Not Work
If you are using .htpasswd to protect your /wp-admin/ folder, AJAX request to /wp-admin/admin-ajax.php will not work. This problem is not unique to my plugin. Any WordPress Plugins that uses the WordPress AJAX API will break. As mentioned in this Codex, Hardening WordPress:

Simply securing the wp-admin/ directory might also break some WordPress functionality, such as the AJAX handler at wp-admin/admin-ajax.php

To bypass this, check out this tutorial, Password protecting the wp-admin directory, this tutorial will teach you how to whitelist admin-ajax.php in your /wp-admin/ using .htaccess.

I still hope in the future version of WordPress, they will separate front facing AJAX requests vs backend AJAX requests.

Your WP-Admin Is HTTPS While Your Site Is Not
If your WP-Admin is behind SSL aka HTTPS and you have the following config in your wp-config.php define('FORCE_SSL_ADMIN', true);, the AJAX will fail because https://yoursite.com is different from http://yoursite.com and the browser treat it as different domain.

To solve this issue do the following:
Find:
'ajax_url' => admin_url('admin-ajax.php'),
Replace:
'ajax_url' => admin_url('admin-ajax.php', (is_ssl() ? 'https' : 'http')),

What the code does is basically forcing http to be used when calling admin-ajax.php for AJAX request. Again this is a hack, I am trying to figure a way around it.

I have pushed the code to trunk of all the respective plugins.

1 Star2 Stars3 Stars4 Stars5 Stars (411 votes, average: 4.16 out of 5)

53 thoughts on “AJAX Not Working For WP-Email, WP-Polls, WP-PostRatings or WP-PostViews?”

  1. I already did it Lester, but like I said before, problem is still present… I do not want to uninstall and reinstall because I manually translated it, but maybe I need to do it anyway… You think the issue dissapear after a reinstallation? Any other advice?

  2. I don’t have much advice because I am pretty sure it is not a plugin problem because it works fine on my tests. I am leaning towards a plugin conflict or data corruption. The only way around it is to uninstall and reinstall it, not just WP-PostRatings but the previous ratings plugin you are using.

    Also do note that by uninstalling the previous rating plugin, doesn’t mean that the rating data is gone. The uninstall might not delete the data.

    If you ask me, I would say spin up a new WP installation with your theme, WP-PostRatings along side with all the plugins you are using (except the previous rating plugin) to see if the problem still persist.

  3. Thanks Lest, finally problem was solved erasing some previous Post Ratings “users” and “rating” custom field data that I did not noticed before in some old post. All the wp-postratings functionality is normal now.

    Now I would like to know how can I put some text above the stars, something like: Please, rate this entry (or something like this to invite the reader to rate the entry), and in the widget I would like to know how can I force a line break between the post title and the corresponding rating stars. Can I do it?

    Thank you for your kind attention.

  4. uh..? Sry, but I can not find any “Ratings” folder inside my wp-admin folder… r u sure?
    I did not know that I could find plugin’s related files inside this folder…

    Just in case, I looked in my wp-content->plugins->wp-postratings->postratings-templates.php but I think this is not what you refer to and it seems very complex to me…

  5. Lester,
    I’m using wp-polls with W3TC. I’ve emptied the cache which works to fix the “Failed To Verify Referrer” message for a short time. But the error keeps returning. Is there anything more permanent I can do? I’ve even attempted turning off the JS Minify setting.
    Thanks for your help!
    Shawn

  6. Did u try turning off all the js optimisation? Like concatenation? So that it will load the WP-Polls JS instead of using W3TC to load it? The JS is already min on WP-Polls

  7. Hi,
    first at all, thanks for your great plugin !
    I’ve a problem when i’m try to rate a post when i’m not loggin as admin:
    The ajax event load the login page ( i’ve set that everybody can rate register and guest)…
    Did you know hopw i can fix it ?
    thanks

  8. Thank you very much, i just fix an issue on my wordpress installation with your code fore “WP-Admin Is HTTPS While Your Site Is Not”.

  9. Hi Lester,
    I’ve been using WP-Email plugin on many of my websties. It stopped working after update. It shows “Failed To Verify Referrer” when email is forwarded.
    I’ve read your replies on this post and on WP forum. I don’t use any cache or minify plugin. Clearing browser cache didn’t help either.

    Any other solution to try?

    Tx

  10. You sure you are not using any caching or minifying plugin? The other one I can think of is there is a JS error somewhere in your site? Do you have any site that I can with the problem?

  11. Hi Lester, i came across the same problem. Things is i’ve had many issues with the Cache plugin, so i uninstalled it. Even for your plugin WP PostRatings. But still, the “Failed to Verify Referrer appears quite often on some articles, not all (especially on the main page).

    If you can have a look and tell me how can i fix that, that would be amazing. Thanks !

  12. @Laurent: nice site, love the way you customised the plugin. I can’t seem to find any issue with yours. I rated 3 posts, from the home page as well as the single post page. Works fine.

    I am using FF & Chrome

  13. Thanks Lester ! Yes, i wanted to customize a little bit your great plugin to fit with my project ! Anyway, i tried with Safari and it seems that the cache from Google Chrome made some mistakes. Everything’s working great !

    Another question, i’m planning to makes user profiles ont the next version of my site and wanted to know something. For exemple if someone stars a post or videos, i want that is reported on the user profile (like : “User love that video or post”). Do you think that your plugin could provide some of these implements or do i need to get another script ?

    Thanks for your answers !

  14. If the user is logged-in, it will be captured in the logs. WP-Admin -> Ratings -> Manage Ratings, but you have to write down your own script to query the table wp_ratings table and retrieve that info. It is not in the plugin =)

Comments are closed.