Ajax return the wrong data
-
I’m writing my own login Ajax procedure, and everything work just fine when the credential are correct, (the user is logged in as it is supposed to do); but when the there is a mismatch in the credentials, Ajax return the whole page instead of the JSON data I wrote and I expect to return.
Here below is the php function headlining the Ajax request. Can someone please tell me what an i doing wrongfunction prt_login(){ if ( check_ajax_referer( 'wp_rest', '_wpnonce' ) ){ if ( $_POST['remember'] == 'true' ) { $rmbr = true; } else { $rmbr = false; } $cred = array( 'user_login' => $_POST['user_name'], 'user_password' => $_POST['password'], 'remember' => $rmbr ); $login_ststus = wp_signon( $cred, true ); if( is_wp_error( $login_ststus ) ){ echo json_encode( array( 'status' => false, 'message' => 'Wrong login credentials.' ) ); die(); } echo json_encode( array( 'status' => true, 'message' => 'The login was succesfull. Reloading the page...' ) ); } else { // if the nonce is not verified die(); } die(); }
Any suggestion is very much appreciated, thanks in advance
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Ajax return the wrong data’ is closed to new replies.