weixin_33737134 2016-02-06 22:44 采纳率: 0%
浏览 15

JQUERY回应无法运作

I have an ajax that sends an email with some information, and then responds sent or notsent, my problem is that i dont know why the if after the .done for ajax should do something if the respond is "sent" according to the inspector the respond is sent but it always goes to the else in my if sention, and i have no idea why, the email is sent and everything but i just cant understand why always goes to the else.

my jquery is like this:

function Send()
{
    var nom = $('#name').val();
    var ape = $('#lastname').val();
    var occ = $('#occupation').val();
    var dep = $('#department').val();
    var dob = $('#datob').val();
    var bdp = $('#place').val();
    var add = $('#address').val();
    var cid = $('#cidnumber').val();
    var pho = $('#phone').val();
    var pem = $('#mail').val();
    var sta = $('#station').val();
    if(bdp == '' || add == '' || cid == '' || pho == '' || pem == '')
    {
        swal("Ooops!", "All the information MUST be filled, Please check!.", "error");
    }
    else
    {
        $('#myModalEmail').modal('toggle');
        $.ajax({
            url: 'AccionesPHP.php',
            type: 'POST',
            data: {funcion:'SendIdMail',name:nom,lastname:ape,occupation:occ,department:dep,dob:dob,place:bdp,address:add,companyid:cid,phone:pho,mail:pem,station:sta}
        })

        .done(function(respuesta){
            if(respuesta == "sent")
            {
                $('#myModalEmail').modal('hide');
                swal("Success!", "Your Card Request has been sent successfuly.", "success");
                LoadData();
            }
            else
            {
                swal("Ooops!", "This is embarrasing, we have a proble could you try later, Error!.", "error");
            }
        });
    }
}

And my PHP is like this:

$name = $_POST['name'];
        $lastname = $_POST['lastname'];
        $occupation = $_POST['occupation'];
        $department = $_POST['department'];
        $dob = $_POST['dob'];
        $place = $_POST['place'];
        $address = $_POST['address'];
        $companyid = $_POST['companyid'];
        $phone = $_POST['phone'];
        $mail = $_POST['mail'];
        $station = $_POST['station'];
        //ENVIO DE MAIL PARA DAVID WING

        $mensaje = '<html>'; 
        $mensaje .= '<body>';
        $mensaje .= '<h3> New Company Identification Card Request </h3>';
        $mensaje .= '<div><p> The information for the Card request is below:</p>';
        $mensaje .= '<label>Name</label>';
        $mensaje .= '<input type="text" value="'. $name .'" disabled><br<br>';
        $mensaje .= '<label>Last Name</label>';
        $mensaje .= '<input type="text" value="'. $lastname .'" disabled><br<br>';
        $mensaje .= '<label>Occupation</label>';
        $mensaje .= '<input type="text" value="'. $occupation .'" disabled><br<br>'; 
        $mensaje .= '<label>Depatment</label>';
        $mensaje .= '<input type="text" value="'. $department .'" disabled><br<br>'; 
        $mensaje .= '<label>Date of Birth</label>';
        $mensaje .= '<input type="text" value="'. $dob .'" disabled><br<br>';
        $mensaje .= '<label>Birth Place</label>';
        $mensaje .= '<input type="text" value="'. $place .'" disabled><br<br>';
        $mensaje .= '<label>Address</label>';
        $mensaje .= '<input type="text" value="'. $address .'" disabled><br<br>';
        $mensaje .= '<label>Company ID</label>';
        $mensaje .= '<input type="text" value="'. $companyid .'" disabled><br<br>';
        $mensaje .= '<label>Phone</label>';
        $mensaje .= '<input type="text" value="'. $phone .'" disabled><br<br>';
        $mensaje .= '<label>Personal e-mail</label>';
        $mensaje .= '<input type="text" value="'. $mail .'" disabled><br<br>';
        $mensaje .= '<label>Station</label>';
        $mensaje .= '<input type="text" value="'. $station .'" disabled><br<br>';
        $mensaje .= '</body> </html>';

        $para = '[email protected]';
        $titulo = 'New Company Identification Card Request';
        $cabeceras = 'MIME-Version: 1.0' . "
";
        $cabeceras .= 'Content-type: text/html; charset=iso-8859-1' . "
";
        $cabeceras .='From: [email protected]' . "
" .
                    'Reply-To: [email protected]' . "
" .
                    'X-Mailer: PHP/' . phpversion();

        if(mail($para, $titulo, $mensaje, $cabeceras))
        {
            print "sent";
        }
        else
        {
            print "notsent";
        }

        break;
  • 写回答

2条回答 默认 最新

  • weixin_33711641 2016-02-06 23:03
    关注

    Yes, the email is sent, the 'respuesta' is where i get the data from php which should be "sent" or "notsent" which comes from the if (mail ()) if it's true returns "sent" which is working according to the inspector i get "sent" as answer but still when i do if (respuesta=="sent") Do something

    Else Do something

    Idk why it always go to else if the answer from php is "sent"

    评论

报告相同问题?