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
- Validate a custom form with js and php
- How can I process a form submission from an HTTP POST request?
- Add Server Side validation in Ajax mail form
- List sub categories and corresponding posts of a parent category
- population category dropdown and sub category onselect
- jquery & ajax getting data from php in wordpress . admin-ajax.php returns 400
- Failed to load resource: the server responded with a status of 500 (Internal Server Error) through wp_admin_ajax.php
- Store ajax data in PHP variable
- Settings API form – submit with AJAX
- My Custom Post Type AJAX Query is Returning no posts – why?
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- Post form – AJAX won’t upload featured image – Plugin development
- $_POST returning empty values
- Search bar for wp menu
- Adding HTML Code to Replace Text in PHP
- Hide A Class and Add Custom HTML Code Using WordPress
- Fatal error login WordPress [duplicate]
- Executing php on button press
- Trying to update Woocommerce meta values
- How to send custom form submissions to WordPress Database?
- Add other class content with reference class value
- Shortcode in Shortcode/HTML Graphics and Pictures
- Load more posts using AJAX based on posts inside WP_Query
- Multiple AJAX handler functions conflict in functions.php
- Change ajax live search results
- PHP function for horizontal Woocommerce thumbnails and badges
- How to call my PHP function with AJAX ? wp_query
- PHP calling AJAX function that relies on passed PHP function values not working
- Ajax result show in console if is called outside function and not showing in array
- Can’t pass var from php wp_ajax into ajax script : result undefined or null
- Custom PHP form needs refresh to load page correctly
- What are the advantages/disadvantages of ways to use php template files?
- Using Google Analytics in an enqueued JS file
- I can’t go to the page archive-{post_type}.php
- Ajax filter with loadmore button
- Admin-ajax.php 404 error
- Configure WordPress to Use Responsive Image Rendering
- Where to add my PHP codes for AJAX Jquery to work?
- Adding ELSE argument to AJAX Live Search for “No results found”
- How to use data URL in WordPress?
- Form from within a page
- How can i find wrong word in search box and replace with correct word
- How to pass values from one function to the other using an array variable
- HTML comment cause issue in functions.php script root
- dynamic php menu with hidden sub-categories only showing when the category name is clicked
- Slug duplicates once clicking on link
- couldnt show short code atts in category
- Add Link to PHP message
- separate list of programs in html/javascript coming from php
- I want it to detect the duplicate comment and give a warning on the same page
- Updating user meta adds string count to value?
- PHP multiple forms, same page, isset($_POST[]) not working?