简体   繁体   中英

AJAX-Request: /wp-admin/admin-ajax.php 403

I created a wordpress plugin for calculating costs. The form have only one input-field and a submit button. On submitting the form I'd like to create a ajax request. So, I call the /wp-admin/admin-ajax.php- Url ,but I get the forbidden-Error-Code 403. I thought the entries in the htaccess are wrong, but I get the same error after changing the file and restarting the server.

Do you have any idea what's going on here?

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# admin-ajax.php & post.php skip/bypass rule
RewriteCond %{REQUEST_URI} (admin-ajax\.php|post\.php) [NC]
RewriteRule . - [S=2]

</IfModule>

# END WordPress

It gives 403 forbidden error if you didn't declare that ajax call is allowed.

//allow this particular AJAX function for logged in users
add_action('wp_ajax_myajax', 'myajax');

//allow this particular AJAX function for non-logged in users
add_action('wp_ajax_nopriv_myajax', 'myajax');

    function myajax() {
        //your code
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM