Simply add a Success callback to your Ajax function:
$('#sendEmail').click(function(){
$.ajax({
type: 'POST',
url: 'www.example.com/email.php',
data: { content: $('#email-data').html()},
success: function(data) {
//data variable can be used if your ajax call returns something
do_stuff_here();
}
});
});
In your case, you could do something like
success: function() {
$('body').append('<div class="success">Success!</div>');
}
However, is there a reason you don’t want to use a and the .submit() method?
(http://api.jquery.com/submit/)
Also, don’t forget to validate 🙂
Related Posts:
- wp_mail 200 response but no mail sent
- Send email via ajax
- Adding user using admin ajax by a user with custom role
- Sending email with wp_email and AJAX
- Run PHPMailer function after ajax function completes that adds row to custom table
- Access-Control-Allow-Origin error sending a jQuery Post to Google API’s
- JavaScript implementation of Gzip
- WordPress AJAX with Axios
- Why might a plugin’s ‘do_shortcode’ not work in an AJAX request?
- Get Previous & Next posts by Post ID
- Nonces and Cache
- wp_mail script with jQuery post
- REST API endpoint for elasticpress autosuggest
- ajax – why multiple calls to wp_create_nonce() return same value?
- AJAX request on the frontend always returns 0 if user is not admin
- Using ajax on categories and wordpress loops
- How to modify wp_ajax function?
- Turn jQuery.ajax() request into XMLHttpRequest (vanilla JavaScript)
- wp_remote_get() to get AJAX url /wp-admin/admin-ajax.php
- Can’t seem to get wp_localize_script to work
- Ajax – gettext without a plugin
- WordPress AJAX calls not detecting language properly?
- AJAX issue – Uncaught SyntaxError when processing Zip File
- wp_verify_nonce doesn’t return true on server when it matches the nonce
- update_user_meta doesn’t work with AJAX
- Ajax stops working when logged in?
- WordPress ajax get content post id
- Using wp_handle_upload and media_handle_sideload with ajax
- Create Page With wp_insert_post() and AJAX
- Load ajax if is_home()
- How to know what page is calling admin-ajax.php?
- Populate a Map at The Same Time as showing Posts via AJAX
- wp_localize_script not working on ajax response
- Get wp_title wp ajax
- Why Does WordPress not output admin-ajax.php path by default?
- Ajax custom search not functioning as expected
- Jetpack Infinite Scroll – Add more than 7 posts each time?
- PHP 8, AJAX mail form to function.php doesn’t work
- Speed/Performance difference between `wp_ajax` and `init` checks for AJAX/POST requests?
- Test WordPress api with postman
- Remove trailing 0 from function that is used both statically and dynamically
- How to load next and previous posts by Ajax
- Update attachment metadata fails
- Nonce fails on ajax save
- WordPress ajax works on FF but not on IE & chrome
- Disallow second login session
- WordPress P2 live problem
- Dynamically add more fields/remove last field in a form
- Ajax Request for both logged and non logged users
- AJAX call inside plugin class not triggering
- Contact form 7 Hide response messages after 5 seconds
- WordPress Heartbeat API cannot parse data
- Cache plugins and ajax nonce verification
- Ajax function on #publish only saves as draft – how to make it publish?
- AJAX call broken after actualization
- WP_Ajax Hook doesn’t execute this PHP code
- Ajax function not returning any results
- post values to custom post type which has advanced custom fields
- ajax problem – function on server is not called
- wp_mail doesn’t work when logged in?
- How to continuously send feedback via AJAX responses to my client?
- get current taxonomy post with ajax
- Need help with Access-Control-Allow-Origin
- wp_ajax handler with multiple class instances
- admin-ajax.php (aborted) error when using jQuery.get
- Storing temporary data for a custom post type
- I get a 0 after the result of my ajax requests
- Load page HTML content through AJAX
- Not getting an ajax readystatechange on my page
- Including ‘wp-load.php’ after another include() generates an error
- How to make pages that arent indexed for ajax applications
- admin-ajax.php 400 bad request
- edit user input data contact form 7
- WordPress POST AJAX call, var_dump($_POST) NULL and AJAX response empty when inside ob_start
- How to keep scripts persistent during admin-ajax process when saving widget?
- Very weird bug: Ajax for non-admins
- jQuery ajax method does not return data
- WordPress 403 error on form submission with Ajax
- I am getting Admin-ajax.php 400 Error
- Ajax and get_template_part
- Download doccument on server rather than clients browser
- How to require files in a custom endpoint
- Load oEmbed iframe within ajax call
- Adding pagination to Ajax Query
- Get post details with pure javascript ajax
- WorddPress website admin part not working correctly – I think ajax/json issue
- check_admin_referer fails on new AJAX plugin uninstall with “Are you sure you want to do this?”
- Ajax Security regarding user priviliges and nonces
- How to populate data from JSON using AJAX in TypeScript? [closed]
- Use ajax without a plugin?
- Know which script/page is being called by ajax call
- Trying to send AJAX data to WordPress hook
- wp_enqueue_media problem
- Update user meta using Ajax on front end?
- retrieving page content per AJAX [duplicate]
- Can’t access data from database using AJAX
- how can i create get request unis ajax without expecting return value
- How to use Ajax with WordPress
- Using $.ajax getting 500 error
- admin-ajax.php 400 (Bad Request) what am I doing wrong?