ajax结果显示错误

I have a simple problem but I couldn't find out the solution. the below code is my POST ajax code.

once Its submitted I got the result from the PHP file. once this alert is work alert(addcenterresult);

if OK its alerted 1 if not 2 but the result if every time showing alert ("SomeThing Wrong");

I checked my PHP everything is good. I assumed the error in my ajax code but I found nothing !!!

Please can you help

$('#add-jeddah').click(function () {
    var centername = $('#JeddahCenterNAme').val();
    var dataString = 'centername=' + centername;

    if (centername == '') {
        alert("Please write the center name");


    } else {
        // AJAX Code To Submit Form.
        $.ajax({
            type: "POST",
            url: "func/addjeddahCenter.php",
            data: dataString,
            cache: false,
            success: function (addcenterresult) {
                alert(addcenterresult);
                if (addcenterresult == "1") {
                    alert("Well Done");

                } else {
                    alert("SomeThing wrong");
                }
            }
        });


    }

    //  END add-Jeddah function
});

My PHP

$nameCenter = $_POST['centername'];
$addresult = "INSERT INTO centers (id,centerName) VALUES ('','$nameCenter')";

if (mysql_query($addresult)) {
    echo "1";
        } else {
             echo "2";
    }

Try using the jquery trim when you match the condition equal to 1 or 2 ,sometimes whitespace is returned with the string

give a try to following lines

if ($.trim(addcenterresult) == "1") {
    alert("Well Done");
} else if ($.trim(addcenterresult) == "2"){
    alert("SomeThing wrong");
}

This would also verify that the response you receive is either between 1 or 2 only.