在不同的服务器上获得不同的代码结果

enter image description hereThis is updated based on an answer, but i still have a problem.

var dataString = $("#acc_form").serialize();
var action = $("#acc_form").attr('action');

$.ajax({
type: "POST",
dataType:"JSON",
url: action,
data: dataString,
success: function(res){
                if(res.status === 'error'){
                    console.log('Error!!!');
                } else{
                    console.log('Success!!!');
                }
            }


});

Here is where i do the check, and also where i am confused. my else statement looks wrong.

$desired_email = strip_tags(@$_POST['email']);
$email_exist_check = mysqli_query($connect, "SELECT * FROM accounts WHERE email='$desired_email'") or die(mysql_error());
$email_exist = mysqli_num_rows($email_exist_check);
if ($email_exist == 0) {
    //performs insert query

    } else {

header('Content-type: application/json');           
$res['status'] = 'error';    

echo json_encode($res);  

            }

Any help is greatly appreciated. I am new to jQuery and ajax and using json

Because you've returned a json array, even check email is invalid. You need to process the response data in success of ajax function. The error callback only works when server return status code on header (it isn't status in response data), i called it is Solution 1. In Solution 2, i solve it by return a header in PHP code.

Solution 1: Solve it on client (javascript)

//...
success: function(res){
// Use json parse method to parse the response data if it is string.
// If you have been to set dataType: 'json', it's ok. Can ignore this comment & code.
// res = JSON.parse(res);

status = res.status;

if(status == 'error'){
//Process the error in here
}
}
//...

Full ajax function example:

$.ajax({
                url: 'index.php',
                data: {email: 'vuong@gmail.com'},
                method: 'POST',
                dataType: 'json',
                success: function(res){
                    if(res.status === 'error'){
                        console.log('Error!!!');
                    } else{
                        console.log('Success!!!');
                    }
                }
            });

It's work on my workplace!

My development Network tab on Chrome

Solution 2: Solve it on server (php)

// Add it to before `echo` line
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);

You only need to choose once in both. Good luck!

Sorry all because my English is not good.