WordPress Ajax call not working in Firefox
-
0
down vote
favorite
I have set up different AJAX calls in my WP site and everything works fine, except one specific AJAX call and only in Firefox.I give below the details to reproduce the problem. It includes login credentials, but it is a WP test site and these are fake credentials, so don’t worry, you can use it.
Go to https://responsive.knowledgeplaces.com
Login with credentials [removed from public forum]
Once connected, you will see different buttons. These are buttons for testing purposes.
For instance, you can click on the button “no lpId parameter”, and you will see an error message.
All these buttons trigger AJAX calls on the server, and an alert message is displayed if some validation went wrong on the server.
All these buttons work fine and you will see the alert message on any browser, including Firefox.
There is another button “deconnexion” (logout) on the upper right side of the page.
When you click on this button, you are logged out from the site.
The button works fine on Chrome and IE, but not on Firefox.
Here is how it is implemented.
First, there is a javascript file with the following code:
$("a[href='/kps_logout']").on('click', function() { // check href symbolic URL jQuery.post( WP_AJAX_URL, { 'action': 'kps_logout', 'security': $("#kpcms-ajax-nonce").val() } ); // redirect and deactivate default navigation window.location.href = $kps_Host + $kps_LoginPath; return false; });
Basically, I use a symbolic ‘/kps_logout’ URL, and this JQuery code maps a logout function on any href with this link.
On the server, I have this code in the “functions.php” of my WordPress child theme:
add_action( 'wp_ajax_kps_logout', 'kps_logout' ); add_action( 'wp_ajax_nopriv_kps_logout', 'kps_logout' ); function kps_logout() { // security check check_ajax_referer( 'kpcms-ajax-nonce', 'security' ); // logout user and die wp_logout(); die (); }
Once again, works perfectly in Chrome and IE, not if Firefox.
If I activate the network dev tools, it sounds the AJAX call is not even performed in Firefox, while I can see it in Chrome and IE.
On the “no lpId parameter” button, I can see the AJAX call in all browsers, and it works fine on all browsers. And it is implemented exactly the same way.
I have cleared the cache of Firefox but it does not help.
So if you can help me on this, it would be great!
- The topic ‘WordPress Ajax call not working in Firefox’ is closed to new replies.