Cannot load admin-ajax.php. No access-control allow origin*

There are filters for allowed_http_origins and add_allowed_origins. You can use them to set the proper Access-Control-Allow-Origin header in the response to your AJAX call. Add this to your theme’s functions.php file: add_filter(‘allowed_http_origins’, ‘add_allowed_origins’); function add_allowed_origins($origins) { $origins[] = ‘https://www.yourdomain.com’; return $origins; }

Basic question on passing variables to AJAX in WordPress

The simple answer: Don’t bother with the Admin AJAX API, use the REST API! Tell WordPress about your endpoint: add_action( ‘rest_api_init’, function () { // register dongsan/v1/whatever register_rest_route( ‘dongsan/v1’, ‘/whatever/’, array( ‘methods’ => ‘POST’, // use POST to call it ‘callback’ => ‘dongsan_whatever’ // call this function ) ); } ); Now we have an … Read more

Ajax request returning full page code

My issue was simple; jQuery.post(MyAjax.**ajax_url**, data, function(response) { was meant to be: jQuery.post(MyAjax.**ajaxurl**, data, function(response) { problem solved… sorry

Custom PHP endpoint for a plugin’s AJAX call

First of all, you shouldn’t call your own PHP file. You should use admin-ajax endpoint. Documentation On admin side, you could use ajaxurl to get URL for AJAX calls. On front side you have to declare by yourself variable with url. This is written in documentation: Note: Unlike on the admin side, the ajaxurl javascript … Read more

Using ajax on categories and wordpress loops

Yes this is possible with WordPress but I would not use index.php but a custom front-page.php template then create a page called home and set it as the front page in options-general. For your category menu: <?php $categories = get_categories(); ?> <ul id=”category-menu”> <?php foreach ( $categories as $cat ) { ?> <li id=”cat-<?php echo … Read more

Saving (Updating) Post / Page Edits With AJAX

The german (core) developer Dominik Schilling/ocean90 has released a pretty nice, simple and small plugin to encounter (part of) this problem. Instead of adding a complex AJAX save process, that would just make it harder to work with even handlers and such (de- & re-registering them), he just added a position marker, that allows WP … Read more