The problem is that you’re attempting to use the arguments for the jQuery AJAX API with the native Fetch API. Specifically, the problem is that the JS Fetch API doesn’t support a data
argument.
For an admin-ajax.php request to work in WordPress the $_REQUEST['action']
property needs to be populated, and to do this with the Fetch API you need to pass a FormData object to the body
parameter:
var data = new FormData();
data.append( 'action', 'aj_ajax_demo' );
data.append( 'nonce', aj_ajax_demo.aj_demo_nonce );
fetch(aj_ajax_demo.ajax_url, {
method: 'POST',
body: data,
}).then(response => {
if (response.ok) {
response.json().then(response => {
console.log(response);
});
}
});
Related Posts:
- do_shortcode inside AJAX callback
- How can I run shortcode after click with ajax
- Ajax not returning anything on form submit
- How to use shortcodes on a widget sidebar when doing an ajax call?
- Shortcodes not working in an AJAX call
- How to get gallery id inserted to a post?
- Different uniqid when calld in wp_localize_script and shortcode
- How to add AJAX in a custom PHP function using Google sheets API
- AJAX and Shortcode with Parameters
- wp_editor in thickbox
- do_shortcode via ajax
- Pass data back to TinyMCE from Thickbox
- Getting error on submitting form using Ajax with shortcode
- Regenerating WordPress shortcodes based on value with AJAX
- Use Contact Form 7 with Ajax
- AJAX and do_shortcode
- Remove a short code and update it’s content (AJAX)
- Cannot modify class property from shortcode handler function
- Use Shortcode on Custom Page
- Do embed shortcode on wordpress ajax request
- Ajax callback and shortcode functionality
- Load next post by ID on a single page
- Access Shortcode in ajax code?
- load plugin with ajax [duplicate]
- Why is my ajax live search not working when i use a shortcode to call it?
- How to handle Ajax Calls, when using same shortcodes (with different parameters, e.g. ‘post-type’)?
- Working with Shortcode, AJAX, Elementor
- Custom shortcode being executed when saving page in wp-admin
- Change appearance of shortcode text inside editor
- Shortcode output always showing at top of page
- How can I just get content inside a shortcode or just outside
- How to: How do I make my own shortcodes without plugins?
- Create a shortcode in WordPress, again
- gutenberg widget outputting paragraph marks
- How to make shortcode output display where I choose
- Add Shortcode to a Div or Header [closed]
- Change link in get_terms if there is only one post in the category
- How to get total number of shortcodes in the wordpress application?
- How to change the page break numbering?
- WordPress display image link in shortcode
- stop shortcode stripping in category and archive pages
- How does one insert a variable value into a “myCRED plugin shortcode [closed]
- Enumeration Contact form using database table’s numbe of rows [closed]
- Nested Code Snippets [closed]
- How do I display “Hello username” if logged-in on the homepage
- Adding a Cookie Session to Shortcode Content
- Gutenberg Block with Select from JSON-File
- Shortcode function executed twice?
- add widget to page content (using shortcode)
- Pagination for a page created by the shortcode “Product”
- How to use the same shortcode with different attribute values on same page
- WordPress messes up with data attributes in shortcode output
- WordPress post pagination continuous [duplicate]
- custom field value as shortcode parameter
- Short code template + ajax
- Shortcode don’t work in custom option field, any solution?
- Slow page Loads When Using Dynamic Coding
- Can I use shortcodes in mail body
- Position shortcode off [duplicate]
- Query to list all galleries under a parent post?
- Adding the username into a URL to redirect to a specific page
- Shortcode Help Needed → attributes
- Ordering get_terms with ACF not displaying all terms
- How to Get Shortcode in Excerpt to follow Document Flow
- Cant fix this Warning: Invalid argument supplied for foreach() in [closed]
- Different ID in every shortcode
- Unique ID for WordPress shortcodes when used more than once on a page?
- How to find out what handler is registered to a shortcode
- AJAX function not working [closed]
- Build Clickable Link Using Multiple Attributes
- Using Shorcodes in Sharing Preview and Notifications Title from Post Title
- Is the WP audio shortcode still relevant?
- Third-Party API – PHP Fatal Errors Paired with http_request_failed / cURL error 28
- Using within a shortcode
- Shortcode not working when I output data from wpdb html table row
- How do I point bloginfo(‘stylesheet_directory’) to my parent theme?
- How to avoid one code multiple times instead do that through some function? Shortcode, but I think shortcode is not used in main theme’s core files?
- How to list child pages with excerpts, e.g. [child-pages depth=”1″ excerpt=”1″]
- Add a shortcode in woo-function.php
- Get current category and place it in shortcode
- Woocommerce products shortcode specific order
- Modify Blog Module layout in Child theme
- Video shortcode outside WordPress not working with IE and mediaelement’s Flash fallback
- Display title of child pages in shortcode
- Output html source tags inside shortcode
- How can I define the output of shortcode attribute value?
- Using shortcodes that wrap around code
- How to load a plugin when doing an Ajax call? [duplicate]
- What is the best way to include a template file within a shortcode?
- Shortcode templates
- Create plugin/function to catch XML-data via Shortcode
- Why My slider shortcode display above header
- Does anyone recognize shortcode ig_special_heading?
- How to scroll to a shortcode-generated anchor
- add post type pram to wp shortcode
- Shortcode conversion to hrml when post is published
- Shotcode error on functions
- Shortcode for displaying the user’s first name?
- Can I prevent wordpress adding and tags to autoembeds
- Shortcode – Display inline icon before text [closed]