Title: Not a Valid Json Element
Last modified: February 23, 2023

---

# Not a Valid Json Element

 *  Resolved [krishnathapa](https://wordpress.org/support/users/krishnathapa/)
 * (@krishnathapa)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/not-a-valid-json-element/)
 * 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 ]_
 *     ```wp-block-code
       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](https://wordpress.org/support/users/dudo/)
 * (@dudo)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/not-a-valid-json-element/#post-16500609)
 * Hello!
   Most probably it is a caching issue.Delete all your caches and then try
   again
 *  Thread Starter [krishnathapa](https://wordpress.org/support/users/krishnathapa/)
 * (@krishnathapa)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/not-a-valid-json-element/#post-16500648)
 * 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](https://wordpress.org/support/users/krishnathapa/)
 * (@krishnathapa)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/not-a-valid-json-element/#post-16500924)
 * 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](https://wordpress.org/support/users/dudo/)
 * (@dudo)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/not-a-valid-json-element/#post-16502716)
 * 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](https://stackoverflow.com/questions/9408334/wordpress-admin-ajax-results-in-error-302-redirect)
   Let me know!
 *  Thread Starter [krishnathapa](https://wordpress.org/support/users/krishnathapa/)
 * (@krishnathapa)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/not-a-valid-json-element/#post-16504337)
 * Thank you. I think I am very close to solution now. 
   I found the code in the 
   functions.php which is causing issue.
 *     ```wp-block-code
       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](https://wordpress.org/support/users/krishnathapa/)
 * (@krishnathapa)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/not-a-valid-json-element/#post-16504895)
 * Hi, 
   I found the solution. Here is the final code which fix this issue.
 *     ```wp-block-code
       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](https://wordpress.org/support/users/dudo/)
 * (@dudo)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/not-a-valid-json-element/#post-16505408)
 * 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.

 * ![](https://ps.w.org/yet-another-stars-rating/assets/icon-256x256.png?rev=1525329)
 * [YASR - Yet Another Star Rating Plugin for WordPress](https://wordpress.org/plugins/yet-another-stars-rating/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/yet-another-stars-rating/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/yet-another-stars-rating/)
 * [Active Topics](https://wordpress.org/support/plugin/yet-another-stars-rating/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/yet-another-stars-rating/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/yet-another-stars-rating/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [dudo](https://wordpress.org/support/users/dudo/)
 * Last activity: [3 years, 1 month ago](https://wordpress.org/support/topic/not-a-valid-json-element/#post-16505408)
 * Status: resolved