This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// if both logged in and not logged in users can send this AJAX request, | |
// add both of these actions, otherwise add only the appropriate one | |
add_action( 'wp_ajax_nopriv_myajax-submit', 'myajax_submit' ); | |
add_action( 'wp_ajax_myajax-submit', 'myajax_submit' ); | |
function myajax_submit() { | |
$nonce = $_POST['postCommentNonce']; | |
// check to see if the submitted nonce matches with the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery('#myForm1').ajaxForm({ | |
data: { | |
// additional data to be included along with the form fields | |
}, | |
dataType: 'json', | |
beforeSubmit: function(formData, jqForm, options) { | |
// optionally process data before submitting the form via AJAX | |
}, | |
success : function(responseText, statusText, xhr, $form) { | |
// code that's executed when the request is processed successfully |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// embed the javascript file that makes the AJAX request | |
// don't forget to specify 'json2' as the dependency | |
wp_enqueue_script( 'my-ajax-request', plugin_dir_url( __FILE__ ) . 'js/ajax.js', array( 'jquery', 'json2' ) ); |
OlderNewer