Can’t seem to get wp_localize_script to work

I tested that code like this: wp_enqueue_script(‘jquery’); wp_localize_script( ‘jquery’, ‘MS_Ajax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ), ‘nextNonce’ => wp_create_nonce( ‘myajax-next-nonce’ )) ); And it works but throws a Notice. It should be hooked to wp_enqueue_scripts like: function my_enqueue_scripts() { wp_enqueue_script(‘jquery’); wp_localize_script( ‘jquery’, ‘MS_Ajax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ), ‘nextNonce’ => wp_create_nonce( ‘myajax-next-nonce’ )) ); … Read more

help on wp_editor via ajax load [duplicate]

I’m not good with English, but the answer is that the editor class calls the scripts needed in the admin footer (wp-includes/class-wp-editor.php line 160) : add_action( ‘admin_print_footer_scripts’, array( __CLASS__, ‘editor_js’), 50 ); add_action( ‘admin_footer’, array( __CLASS__, ‘enqueue_scripts’), 1 ); So when you call the wp_editor function in your ajax, the scripts aren’t printed with it, … Read more

Issue with front-end ajax, getting a 302 redirect when accessing wp-admin/admin-ajax.php

Below function works for me by adding !defined(‘DOING_AJAX’) in condition. function custom_blockusers_init() { if ( is_admin() && !defined(‘DOING_AJAX’) && ( current_user_can(‘usercrp’) || current_user_can(‘userpcp’) || current_user_can(‘subscriber’) || current_user_can(‘contributor’) || current_user_can(‘editor’))) { session_destroy(); wp_logout(); wp_redirect( home_url() ); exit; } } add_action( ‘init’, ‘custom_blockusers_init’ );

Why is my AJAX call not working?

Okay so NOW I have the entire solution. It was two things: Caching was the first part of the issue. Cleared cache, deactivated caching plugin for the time-being. The second, less obvious issue was that, for NOT logged-in users, the response from the AJAX call was returning the entire HTML document in the response area. … Read more

Turn jQuery.ajax() request into XMLHttpRequest (vanilla JavaScript)

Here’s my take on it, although a bit late, but I am working on converting all jQuery.ajax() calls to vanilla JavaScript, so why not. // alpha JS request // no jQuery // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send#Example_POST // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest var request = new XMLHttpRequest(); request.open(‘POST’, fpm_ajax.ajax_url, true); request.setRequestHeader(‘Content-Type’, ‘application/x-www-form-urlencoded;’); request.onload = function () { if (this.status >= 200 && … Read more

How to “Load More” posts via AJAX?

You can use ajax to load more posts on your archive page. attach a js/jquery click event on the More link send ajax request to admin-ajax.php (use wp_localize_script to get the ajax url to front end) with page number (track this with js variable). handle ajax request in php. Add custom ajax actions with add_action( … Read more