• Resolved krishnathapa

    (@krishnathapa)


    Hi,
    I am getting this error when logged in as subscriber. It is fine for non logged in user and when view as logged in user. I am getting this error while using this shortcode. [yasr_visitor_votes ]

    yasr-globals.js?ver=3.2.0:1 Not a valid Json Element
    window.yasrValidJson @ yasr-globals.js?ver=3.2.0:1
    (anonymous) @ visitorVotes.js?ver=3.2.0:1
    i @ jquery-3.1.1.min.js?ver=3.1.1:2
    fireWith @ jquery-3.1.1.min.js?ver=3.1.1:2
    A @ jquery-3.1.1.min.js?ver=3.1.1:4
    (anonymous) @ jquery-3.1.1.min.js?ver=3.1.1:4
    load (async)
    send @ jquery-3.1.1.min.js?ver=3.1.1:4
    ajax @ jquery-3.1.1.min.js?ver=3.1.1:4
    a.ajax @ jquery-migrate-3.0.0.min.js?ver=3.0.0:2
    r. @ jquery-3.1.1.min.js?ver=3.1.1:4
    (anonymous) @ visitorVotes.js?ver=3.2.0:1
    (anonymous) @ visitorVotes.js?ver=3.2.0:1
    (anonymous) @ visitorVotes.js?ver=3.2.0:1
    (anonymous) @ visitorVotes.js?ver=3.2.0:1
    (anonymous) @ visitorVotes.js?ver=3.2.0:1
    yasr-globals.js?ver=3.2.0:1 SyntaxError: Unexpected token '<', ")
    at window.yasrValidJson (yasr-globals.js?ver=3.2.0:1:191)
    at Object. (visitorVotes.js?ver=3.2.0:1:3302)
    at i (jquery-3.1.1.min.js?ver=3.1.1:2:27983)
    at Object.fireWith as resolveWith
    at A (jquery-3.1.1.min.js?ver=3.1.1:4:14203)
    at XMLHttpRequest. (jquery-3.1.1.min.js?ver=3.1.1:4:16491)
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor dudo

    (@dudo)

    Hello!
    Most probably it is a caching issue.
    Delete all your caches and then try again

    Thread Starter krishnathapa

    (@krishnathapa)

    Hi dudo,
    Thank you for your quick response.

    I am getting this issue even while running site locally. There is no cache plugin installed on the site.

    Thank you

    Thread Starter krishnathapa

    (@krishnathapa)

    Hi I found this.
    Do you know why there is 302 status code for this ajax?

    1. Request URL: /wp-admin/admin-ajax.php?action=yasr_load_vv&post_id=7400
    2. Request Method: GET
    3. Status Code: 302 Found
    Plugin Contributor dudo

    (@dudo)

    Seems like you’ve a 302 code when admin-ajax.php is used.

    Most probably it is the theme, or a plugin.
    You can try the solution posted here https://stackoverflow.com/questions/9408334/wordpress-admin-ajax-results-in-error-302-redirect

    Let me know!

    Thread Starter krishnathapa

    (@krishnathapa)

    Thank you. I think I am very close to solution now.
    I found the code in the functions.php which is causing issue.

    if (is_user_logged_in() && is_admin() && !current_user_can('administrator')) {
    	global $current_user;
    	wp_get_current_user();
    	$user_info = get_userdata($current_user->ID);
    	if ($user_info->wp_user_level == 0) {
    		wp_redirect(home_url());
    		exit;
    	}
    }

    I need to redirect subscriber to the homepage when they try to access /wp-admin. When we use this code it is causes with the rating. Could you please suggest how can I redirect without conflicting with the plugin?

    Thread Starter krishnathapa

    (@krishnathapa)

    Hi,
    I found the solution. Here is the final code which fix this issue.

    if (is_admin() && !current_user_can('administrator') && !(defined('DOING_AJAX') && DOING_AJAX)) {
    		global $current_user;
    		wp_get_current_user();
    		$user_info = get_userdata($current_user->ID);
    		if ($user_info->wp_user_level == 0) {
    			wp_redirect(home_url());
    			exit;
    		}
    	}

    Thank you so much for your help!

    Plugin Contributor dudo

    (@dudo)

    Great, thanks for let me know!
    Which theme are you using?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Not a Valid Json Element’ is closed to new replies.