This is how I got AJAX working for me.
-
I digested this tutorial. https://codex.wordpress.org/AJAX_in_Plugins
-
I created an external JS file and enqueued after jQuery because of its dependency on jQuery.
-
I created a PHP function to respond to the AJAX call by echoing what was sent.
-
When that worked, I made the PHP function send the data I needed.
I think what you have should work. If the let
declaration gives you an error, try it with var
instead. This is stupid, I know, but if var
doesn’t work then the error is in the right side of the expression.
I would replace url: '<WP_AJAX_URL_HERE>'
with ajaxurl
and see if that helps.
Related Posts:
- How to store data from multiple forms using ajax and php
- WordPressUser Submission Form
- add_filter the_content str_replace after shortcode
- WordPress Ajax always returns a 404 error
- Load custom field value into div with AJAX
- Custom WordPress+PHP+MYSQL+AJAX form, submit event not captured by Javascript, but does POST data to the DB
- Ajax form submit within a Post Metabox
- Upload Image in a WordPress page using PHP
- Load a page into a div with Ajax
- My form action url is being prepended with a directory that does not exists
- Ajax loaded form replaces form action with Ajax url
- prevent default not stopping page refresh. Passing form information to and from php with ajax in a wordpress site
- Ajax call return 404
- Why Won’t My Inputs in a form with a Get method work together?
- Input data from email form not going to JSON file
- How to get the value of input hidden html from text editor to custom page template?
- Show success or error messages in Ajax response to WordPress custom registration form
- Login to wordpress by clicking a link and specifying usernaname and password in url
- WordPress admin-ajax.php 400 bad request
- Ajax contact form return 0
- Search WordPress using static html page
- HTML escaping data with ajax requests
- How to execute html code inside php?
- Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
- How to add post meta in while loop?
- Adding attribute to the post.php form tag in wp-admin
- Custom forms with HTML
- custom add note meta box with add button in wordpress
- Contact form – problem with displaying message about sent mail
- Using Ajax to submit a form, and run a SQL Select query based on user input from the form
- Cascading dropdown select search based on Parent Page & Child Page
- WordPress cascading dropdown selection search based on Parent Page & Child Page
- Display WordPress search results based on the selected Sub-Category
- HTML Form Question
- How do I call a value from the datase using ajax
- How to change this ajax function to submit to the default wordpress content area instead of the custom field ‘seller notes’?
- How to use wp_ajax_set_post_thumbnail?
- AJAX and custom pages
- wordpress form action page not found
- Pass form attributes to another php template in wordpress
- Code works on page-example.php by not category-example.php
- Submitting my form to the database and then redirecting to payment site
- Ajax call URL 404’ing when pushed to staging server
- Pass the updated value of aid from form using ajax
- Data inserted in database, but ajax calls error function
- ajax form function error
- Load Meta box value into div AJAX [duplicate]
- Word press – JSPDF – Sending PDF as attachment from wp_mail – Special characters
- xajax expanding list query
- What exactly does “Posts page” do in WordPress?
- Real time Duplicate title check
- Blank on static home page?
- WordPress automatically adds tags when pasting code, how to stop it?
- How to create and work with custom data / tables (i.e., for arbitrary data)?
- Trying to implement Ajax comments in WordPress, getting WP error
- Can’t search posts using WP_QUERY inside AJAX Function
- Woocommerce add to cart quantity buttons with AJAX
- Populate dropdown with Child Pages based on Parent Page chosen
- Ajax load more posts with multiple tax query
- Ajax call not working
- Plugins not working on AJAX requests
- How to convert select to HTML with PHP tags inside of it [closed]
- AJAX button action in foreach
- Add Codepen animation as Preloader to WordPress
- Ajax button not working
- Simple AJAX notification when the new post is added to the database
- register_setting & add_settings_error validation issues with multiple fields
- WordPress wp-admin redirect and exception
- Is it possible to create new user from external form using REST API?
- coding a WordPress AJAX Form using PHP to check if User is Logged Out and Show error
- When echo follow Ajax button inside Ajax pagination template not working?
- jQuery Ajax PHP function call returning [object Object]
- PHP Warning: Missing argument 2
- Make a page (url) not cacheable [closed]
- Disclaimer that will show every refresh of the page
- List sub categories and corresponding posts of a parent category
- population category dropdown and sub category onselect
- Failed to load resource: the server responded with a status of 500 (Internal Server Error) through wp_admin_ajax.php
- $_POST returning empty values
- Using Google Analytics in an enqueued JS file
- Ajax filter with loadmore button
- How do I disable cache for a certain page?
- $.ajax results in 403 forbidden
- How can I create a shortcode from an html and php code written together
- How can i get the same ajax result using WP REST API instead of admin-ajax?
- Allowing HTML elements in title widgets spacing problem
- html to posts, jpg to featured image, zip file contains jpg and html
- How do you change the tag font size in the repeater-template.php [closed]
- PHP tag in post content makes wordpress go crazy
- RegExp to EXCLUDE strip HTML (FOR SOMME) comments
- 403 (Forbidden) delete file image in themer folder
- Problems with plugin that fetches data from database with ajax
- How Can I Center the Logo in the Navigation Menu? [closed]
- Dynamic Gallery
- How to pass username into form that sends data to database
- Jquery autosave text area after typing
- Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)
- why is kses removing semicolon from inline style?
- Upload multiple files via ajax from an HTML file input
- How to pass javascript var to php var