Ajax does not fire my function
-
In my javascript file:
jQuery(document).ready( function($) { data={'action': 'check_email_exists','umail': field.value}; jQuery.post( ajax_url, data, function(response) { console.log(data); console.log(response); if(response=='true'){ warning=document.getElementById('email_r'); warning.innerHTML='This email is already taken'; warning.style.display='inline'; warning.scrollIntoView(); return true; } }); });
In my plugin’s php file:
add_action('wp_ajax_nopriv_checkemail', 'check_email_exists'); add_action( 'wp_enqueue_scripts', 'call_external_scripts' ); function check_email_exists(){ global $wpdb; $sql="SELECT id FROM ".$wpdb->prefix."users WHERE user_email = '".$_POST['umail']."';"; //echo $sql; $results = $wpdb->get_results($sql); if($results){ echo 'true'; }else{ echo 'false'; } exit; }
The function is not called.
If I add this to the php file:
if($_POST['action']){ global $wpdb; if($_POST['action']=='check_email_exists'){ $sql="SELECT id FROM ".$wpdb->prefix."users WHERE user_email = '".$_POST['umail']."';"; //echo $sql; $results = $wpdb->get_results($sql); if($results){ echo 'true'; }else{ echo 'false'; } }//*/ exit; }//*/
Then it works. The javascript gets ‘true’ if the user exists and ‘false’ if he doesn’t.
The problem is that the site is borked. Any act of saving a page or a post or editing a user results in a whitescreen.
Baffling…
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Ajax does not fire my function’ is closed to new replies.