Skip to main content

Questions tagged [ajax]

Ajax - The core of WordPress uses Ajax only in the administration screens. For instance, Ajax is used for instant updates when you are doing comment moderation, and when you are adding and deleting items from lists such as categories, blogroll, and posts; Ajax is also the technology behind the auto-save functionality on post and page editing screens. Several themes and plugins also use Ajax; for instance, some post rating plugins.

55 votes
2 answers
25k views

Ajax takes 10x as long as it should/could

I have just hit my first serious issue with WordPress and for someone that enjoys Ajax this is a biggy. I have an Ajax request that is taking 1.5 seconds to complete while using the Ajax API. If I ...
Mike's user avatar
  • 813
51 votes
1 answer
9k views

What's the preferred method of writing AJAX-enabled plugins?

I'm wondering what the preferred method is for dealing with AJAX calls. Should one use the same plugin php file to process the POST or a separate one? Which is cleaner or safer?
James's user avatar
  • 625
45 votes
15 answers
117k views

Admin Ajax is returning 0

I am relatively new to jQuery and AJAX in particular. I have a small issue with the return value always being 0, though I think this is actually the success message and it's not returning anything. I ...
Apina's user avatar
  • 659
41 votes
5 answers
158k views

ajaxurl not defined on front end

I am trying to create a ajaxform on the front side. I am using the code jQuery.ajax( { type: "post", dataType: "json", url: ajaxurl, data: ...
dread_cat_pirate's user avatar
35 votes
4 answers
28k views

How to check if I am in admin-ajax.php?

Right now for my plugin, I am using in_admin() to determine if the user is in the frontend of the site or in the admin area. However, the problem occurs when plugins use admin-ajax.php to process ajax ...
Extrakun's user avatar
  • 1,004
26 votes
7 answers
77k views

Ajax call always returns 0

I have a problem with AJAX returning 0 always! I have done everything by the book and can't figure out what is wrong? Please help!! Here is my Ajax call: //Pass data through AJAX var ...
Kuka's user avatar
  • 277
25 votes
2 answers
6k views

Does the functions.php file ever get called during an AJAX call? Debug AJAX

Trying to figure out an issue a fellow programmer is having. I was wondering if the functions.php file get called at all when you do admin side AJAX? I know that when you do an AJAX call a part of ...
Manny Fleurmond's user avatar
25 votes
8 answers
26k views

How to load wp_editor() through AJAX/jQuery

I have a theme that is custom developed and really complex. One of the things that I have is multiple content areas where users can specify content for specific tabs. I load multiple instances of ...
Aaron Wagner's user avatar
24 votes
8 answers
21k views

Best way to end WordPress ajax request and why?

Considering regular WordPress ajax requests like these: add_action( 'wp_ajax_merrychristmas_happynewyear', array( $this, 'merrychristmas_happynewyear' ) ); add_action( '...
prosti's user avatar
  • 4,313
24 votes
4 answers
108k views

400 bad request on admin-ajax.php only using wp_enqueue_scripts action hook

I've been working on ajax lately. The tutorials you find on the net are all very similar and quite easy to implement. But I always get a bad request 400 on my ajax-admin.php file. After a long and ...
Sin's user avatar
  • 374
22 votes
1 answer
18k views

Why does WordPress add 0 (zero) to an Ajax response?

Unless I end Ajax processing function by exit() or die(), the Ajax function receives desired and correct output but following by 0. Any idea why is that happening? Is that meant to be like that or ...
Radek's user avatar
  • 595
21 votes
4 answers
127k views

How does admin-ajax.php work?

We are having some issues with an external developer. We want to limit access to the wp-admin site to internal access only (via VPN). Simply so it will not be attacked by external users. We can ...
nick's user avatar
  • 211
17 votes
3 answers
12k views

Adding admin-ajax.php to the frontend. Good or bad idea?

I love admin-ajax.php. But I hate having to localize in order to point frontend scripts to it, and I wish there was an equivalent, easy-to-find file for themes. (It also just bothers me to see ...
MathSmath's user avatar
  • 5,598
17 votes
2 answers
5k views

How to load wp_editor via AJAX

Does anyone know how o load wp_editor via AJAX in WordPress? My markup and editor is getting loaded properly but editor controls are not getting loaded properly, it may be because Javascript is not ...
user17108's user avatar
  • 181
16 votes
4 answers
8k views

How to cache json with wp-super cache

In a new project we are using wp-super-cache (the client's preferred plugin) to create the static html files for custom content types. But we are trying to figure out if everything is being cached ...
Starfs's user avatar
  • 507
15 votes
2 answers
39k views

Why use admin-ajax.php and how does it work?

My ajax call for json data works ok like this functions.php: add_action( 'wp_ajax_nopriv_load-filter', 'prefix_load_cat_posts' ); add_action( 'wp_ajax_load-filter', 'prefix_load_cat_posts' ); ...
Claudiu Creanga's user avatar
14 votes
1 answer
14k views

Why use wp_send_json() over echo json_encode()?

When sending a JSON response back to an AJAX request, why use the WordPress function wp_send_json() and not echo json_encode()? What is the benefit of using the WordPress function wp_send_json() over ...
henrywright's user avatar
  • 3,077
14 votes
4 answers
8k views

Load minimum WordPress environment

I made my own upload service for my website that is separate from WP, but uses WP to provide low level db functions and user verification. To do that, I include wp-load.php in my main script (...
MechEngineer's user avatar
13 votes
2 answers
12k views

How would I get a taxonomy/category list inside a Gutenberg block?

I would like to display a dropdown list of categories (or other taxonomy) inside of a Gutenberg block. I can only think of two ways to do this: Create an array of the taxonomy in php and use ...
JakeParis's user avatar
  • 663
13 votes
2 answers
10k views

How can I send data to admin-ajax via JS Fetch?

I'm trying to implement filter system in my website. I decided to make it via js. I created fetch function let filters = document.querySelectorAll('.filters-item'); let pageUrl = wp.page_url; const ...
MMPL1's user avatar
  • 257
13 votes
1 answer
7k views

How to manage ajax calls and JSON in wordpress

I have a custom post type that i want to access through jQuery - preferably using JSON. So first things first. creating a function that returns/echos json is easy enough, but how would I access it ...
Storm's user avatar
  • 233
13 votes
2 answers
4k views

Can I use the same nonce for multiple requests on the same page?

Or does this break the purpose of the nonce, which I admint I don't quite understand it? :) For example on two ajax requests that run on page load, or when something is clicked: $.ajax({ type: '...
Alex's user avatar
  • 133
12 votes
2 answers
17k views

How to get a unique nonce for each Ajax request?

I've seen a couple of discussions about getting Wordpress to regenerate a unique nonce for subsequent Ajax requests, but for the life of me I can't actually get Wordpress to do it-- every time I ...
Tim's user avatar
  • 311
11 votes
2 answers
12k views

Open a Thickbox with content trough AJAX

I added a custom button to the TinyMCE editor, and I want to open WP's Thickbox when I click on it. How can I make it so that the tb_show() function loads the content I want with ajax? // the ajax ...
onetrickpony's user avatar
  • 13.6k
11 votes
1 answer
3k views

Initialize TinyMCE editor / visual editor after AJAX insert

I have a "repeater" style field group on a custom options page. There's an active visual editor in a hidden state, and when the user clicks "add new" the whole row is cloned. I then need to initialize ...
Jack Arturo's user avatar
10 votes
3 answers
21k views

Admin ajax request return 0 with die()

So i'm using this configuration for an AJAX call in the administrative area (like this): add_action( 'admin_head', 'ajaxPerNgg' ); function ajaxPerNgg(){ ?> <script type="text/javascript" > ...
Ivano Mercuri's user avatar
10 votes
2 answers
17k views

WordPress AJAX with Axios

I have a quick question. Did anyone managed to use Axios inside WordPress to do AJAX requests (wp_ajax with action - calling a function) not REST API and how did you do it? It seems that Axios is ...
Ratko Solaja's user avatar
10 votes
2 answers
5k views

Why is die() used at the end of function that handles an Ajax request?

What could go wrong if I am not using die(); after the function that handles an Ajax request? I have noticed that almost all the WordPress Ajax-based code is using it.
user avatar
10 votes
2 answers
9k views

ajax stopped working when not logged in?

Have had an autocomplete field working for months but has stopped working when not logged in? Not sure when but within the last few days or week (not updated wordpress recently). already have; ...
v3nt's user avatar
  • 1,689
10 votes
2 answers
2k views

Why not register shortcodes if is_admin dashboard?

I have noticed that some plugins such as Contact-form-7, Nextgen-gallery, possibly others, have an interesting anti-feature of not registering their shortcodes when is_admin() is true. The ...
NoBugs's user avatar
  • 452

15 30 50 per page
1
2 3 4 5
90