In my application there is notification system, when user click on that icon I want to make ajax call. The problem id it works fine for admin user (Debug : 200 ok), but not for subscriber user (Debug : 301 moved permanently).

Ajax call

$("#notifications-button").click(function() {

    type : 'POST',

    url: '<?php echo get_option('siteurl') . '/wp-admin/admin-ajax.php' ?>',
    success : function(data){



 function implement_ajax() {


    global $wpdb, $user_ID;

    $wpdb->query( $wpdb->prepare("UPDATE wp_frm_items SET alerts_flag = 0 WHERE user_id = '". (int)$user_ID ."'" ));
add_action('wp_ajax_my_special_ajax_call', 'implement_ajax');
add_action('wp_ajax_nopriv_my_special_ajax_call', 'implement_ajax');//for users that are not logged in.

I do not able to get why this not working for subscriber? Is there anything wrong in code?

Thanks In Advance !

  • Show your code that you use to localize the script. – kaiser Mar 9 '12 at 10:35
  • I am not making any kind of separation for specifc user , i just wanted to work this for all – Ajay Patel Mar 9 '12 at 10:38
  • 1
    Not a solution to your question but it would be better to use admin_url('admin-ajax.php') rather than get_option('siteurl') . '/wp-admin/admin-ajax.php'. – Stephen Harris Mar 9 '12 at 10:39
  • 1
    Do you have something like Role Scoper installed?... I've had problems with AJAX and Role Scoper before now. – Stephen Harris Mar 9 '12 at 10:41
  • 1
    @AjayPatel And why did it then work for admin users? URis are the same for everyone... – kaiser Mar 9 '12 at 10:46

The problem is a conflict with the plug-in Role Scoper. Deactivating the plug-in resolves the issue. As an alternative to Role Scoper, (I do not offer this as a recommendation, simply a suggestion), there is the plug-in Members.


Solving by make manual ajax call to test.php page


ini_set('html_errors', 0);
define('SHORTINIT', true);

require '../../../wp-load.php';
require( ABSPATH . WPINC . '/formatting.php' );
require( ABSPATH . WPINC . '/meta.php' );
require( ABSPATH . WPINC . '/post.php' );

// stuff goes here


    global $wpdb;
    $wpdb->query( $wpdb->prepare("UPDATE wp_frm_items SET alerts_flag = 0 WHERE user_id = $uid" ));
  • You'll want to do some nonce checks (and perhaps permission checks), and also, look up how to use $wpdb->prepare. Right now the above would leave your database open to attack. – Stephen Harris Mar 9 '12 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.