Last active
November 25, 2015 01:05
-
-
Save junrillg/89dae7da6d629168c77d to your computer and use it in GitHub Desktop.
Revisions
-
junrillg revised this gist
Nov 25, 2015 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,7 @@ ============================================== PHP FILE ============================================== add_action( 'wp_ajax_sample_action', 'my_action_callback' ); add_action( 'wp_ajax_nopriv_sample_action', 'my_action_callback' ); @@ -25,7 +29,9 @@ function this_script(){ } ============================================== Javascript File ============================================== $( '.submit' ).on( 'click', function(e){ e.prevetDefault(); -
junrillg created this gist
Nov 25, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ add_action( 'wp_ajax_sample_action', 'my_action_callback' ); add_action( 'wp_ajax_nopriv_sample_action', 'my_action_callback' ); function my_action_callback(){ $_POST['his_not_email']; if ( email_exist( $_POST['his_not_email'] ) ) { echo json_encode( array( 'success' => 'true' ) ); } else { echo json_encode( array( 'success' => 'false' ) ); } die(); } add_action( 'wp_enqueue_scripts', 'this_script' ); function this_script(){ wp_enqueue_script( 'handle', 'htt://location.js', array(), false, true ); wp_localize_script( 'handle', 'sample', array( 'url' => admin_url( 'admin-ajax.php' ) )) } ---------------- $( '.submit' ).on( 'click', function(e){ e.prevetDefault(); var email = $( '.input-email' ).val(); $.ajax({ url: sample.url type: 'POST', dataType : 'json' data: { action : 'sample_action', this_not_email : email } sucess: function(respond){ console.log( respond.sucess ); } error: function(e){ console.log(e); } }) } );