简体   繁体   English

获得$ _POST []值后返回的AJAX呼叫

[英]AJAX Call Returning after getting $_POST[] Value

My problem is this. 我的问题是这个。 I have this ajax call: 我有这个ajax电话:

   $.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). var formData有信息(不是问题)。 In "changepassword_ajax.php" I have this code: 在“ changepassword_ajax.php”中,我有以下代码:

$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. ajax调用返回。 So it's not reaching the rest of the code. 因此,它没有达到其余的代码。

Thanks for your help. 谢谢你的帮助。

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.. 一旦您回声了,就开始了响应头...但是,如果没有设置exit()或die(),PHP脚本不会停止,并且它会结束。

Some advices I can give you are .. 我可以给你的一些建议是..

At your JQUERY add 1 param 在您的JQUERY处添加1个参数

dataType: 'json', dataType:'json',

And at your PHP you have to echo Json encoded responde (best is array).. 在您的PHP上,您必须回显Json编码的响应者(最好是数组)。

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

This way at you jquery in the respond you can.. 这样,您可以在jquery中响应。

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. 用ajax成功代码警告res

I think you did a small mistake while writing a code replace line if($_POST('oldpassword') == $clave){ with if($_POST['oldpassword'] == $clave){ 我认为您在编写代码替换行if($_POST('oldpassword') == $clave){if($_POST['oldpassword'] == $clave){

and re-run the code 并重新运行代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM