Not allowed access – theme ajax problem
-
Hello everyone,
I’ve been searching until now and i wasn’t able to fix my ajax code in the theme. I have created an app for my visitors, to receive some reports.After each ajax call from non-logged in (simple visitors) i get “You are not allowed to access this part of the site”. The plugin works fine when i’m logged in as admin.
functions.php
add_action('wp_ajax_nopriv_serp_analiza', 'ajax_serp_analiza'); add_action('wp_ajax_serp_analiza', 'ajax_serp_analiza'); add_action('template_redirect', 'init_seoboost'); function init_seoboost(){ wp_enqueue_script('ajax-request', get_template_directory_uri() . '/framework/js/seoboost.js',array('jquery')); wp_localize_script('ajax-request', 'SB_ajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nextNonce'=>wp_create_nonce( 'myajax-next-nonce' ))); } function ajax_serp_analiza(){ die("End, i can't reach this text"); }
seoboost.js
var j=jQuery; var SEOBOOST=function(){ this.analiza=function(hemail,cuv){ var id=33201; var data={ action: 'serp_analiza', kw:cuv, email:hemail, cid:id, nextNonce : SB_ajax.nextNonce }; //"https://seoboost.ro/wp-admin/admin-ajax.php" j.post(SB_ajax.ajaxurl, data, function(response) { j("#analiza").html("<p>"+response+"</p>"); }); } } j(document).ready(function(){ j("#trimtie").click(function(){ var email=j("#email").val(); var site=j("#site").val(); var kw=j("#kw").val(); j("#analiza").html("Va rugam sa asteptati cateva secunde cat timp raportul este generat!"); var seo=new SEOBOOST; seo.analiza(email,kw); }); });
[Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]
I’m not sure why the “wp_ajax_nopriv_serp_analiza” does not work, or there is other issue ?
I can access even if not-logged in the page admin-ajax and i receive a 0 as it should, but seems that the post request from a non-user is the problem.Thanks in advance for any of your responses!
- The topic ‘Not allowed access – theme ajax problem’ is closed to new replies.