获得$ _POST []值后,AJAX调用返回

My problem is this. I have this ajax call:

   $.ajax({
                url: "./changepassword_ajax.php",
                type: "POST",
                data: formData,
                processData: false,
                contentType: false,
                success: function (res) {

                }
        });

The var formData has info (that's not the problem). In "changepassword_ajax.php" I have this code:

$obj = new All();
$clave  = $obj->CNF_get('admin_clave');

if($_POST('oldpassword') == $clave){
    $obj->CNF_set('admin_clave', $_POST('newpassword'));
    echo "OK";
}else{

    echo "ERROR";
}

After doing this:

if($_POST('oldpassword') == $clave){

The ajax call returns. So it's not reaching the rest of the code.

Thanks for your help.

I think you did a small mistake while writing a code replace line if($_POST('oldpassword') == $clave){ with if($_POST['oldpassword'] == $clave){

and re-run the code

Once you ECHO something there is started respond headers... But your PHP script doesn't stop if there is NOT set exit() or die() and it goes to the end..

Some advices I can give you are ..

At your JQUERY add 1 param

dataType: 'json',

And at your PHP you have to echo Json encoded responde (best is array)..

echo json_encode(array('state'=>"OK"));
exit();

This way at you jquery in the respond you can..

success: function (res) {
    alert(res.state);
}

please use below code

$obj = new All();
$clave  = $obj->CNF_get('admin_clave');

if($_POST['oldpassword'] == $clave){
    $obj->CNF_set('admin_clave', $_POST('newpassword'));
    echo "OK";
    exit;

}else{

    echo "ERROR";
    exit;
}

alert the res in ajax success code.