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
- How can I process a form submission from an HTTP POST request?
- Do I require the use of nonce?
- Inserting Gravity Form checkbox values into Advanced Custom Fields [closed]
- Security – Ajax and Nonce use [closed]
- On update to 3.04 site started recording accents as “á” and “á”, what to do?
- Nice scroll to wordpress
- Is it ok to replace php code with html?
- Implement a multi-value input field where the number of entries is not limited
- How to set a custom path, for ajax image upload folder in admin?
- Blank space at beginning of tag?
- Add HTML Attributes To Anchor Tags In `wp_list_categories()` Function
- How to prevent those PHP variables from being cached on WordPress?
- Use ajax from function.php
- Create onClick Event to Re-load a Widget
- how to remove metadata from the posts of my blog?
- How to use $query->set with post__in?
- Ajax date_query not working past the first iteration
- selected option if current category is the value
- How do I remove the product thumbnail link from a specific div in Woocommerce? [closed]
- [jQuery]Adding shortcode
- Can I use a jQuery Ajax request in Code Snippets Plugin for WordPress?
- Add data-id attribute to child page links
- Use value from Ajax call in PHP function
- A $_POST should occur when submit form but is not?
- PHP Contact form
- Get wp_current_user_id using PHP and MySQL
- PHP: How to access db the right way in plugin?
- How to use wp_send_json() and output the value with ajax?
- how to changes mobile menu toggle breakpoint in WordPress
- What are the advantages/disadvantages of ways to use php template files?
- How to change PHP variables with AJAX request in WordPress
- Remove span tags from WooCommerce Downloads page
- How to enable HTML tags in category description without breaking the category page
- How can I get my WordPress plugin to receive data and relay it in an ajax/php request to a remote server that requires authentication?
- Why is my form going to frontend on html form submission present on the php files inside my custom plugin?
- Input field duplicates on form submit by jQuery
- Access certain Entry in HTML-Table and pass the entry-data in WP not working [closed]
- Custom Post type Ajax search results
- How to create a php page to collect information from a html page
- Can’t make product images clickable
- wordpress ajax return 0
- I need help implement a Javascript code into the PHP file
- Category – “No content found”
- Run insert if no entry otherwise run update with ajax
- Adding instant search to wordpress page
- WordPress – Image href for home menu nav not working
- AJAX & PHP | Call a specific PHP function from a PHP file via AJAX?
- Load php function with AJAX on modal window
- Parse error: syntax error, unexpected ‘}’ in
- Redirect loop upon installation of my plugin
- ‘This Field is Required.’ is Not Displaying on CF7 [closed]
- How to make this shortcode not refresh the whole page when i use it on frontend