jQuery textarea值只给出一个“True”,而不是值

时间:2013-12-28 08:02:39

标签: javascript php jquery html

以下代码: HTML-Form Textarea:

<textarea rows="5" cols="80" id="msg"></textarea><br>

jQuery发送表单:

$.ajax({
        type: "POST",
        url: "source/contact.php",
        data: "email=" + $("#email").val() + "&msg=" + $("#msg").val() + "&phone=" + nr,
        // Display Answer
        success: function(answer){
            alert(unescape(answer));
            $("#form_contact")[0].reset();
        },
        // If sending failed: Display error message
        error: function(){
            alert("Form Sending Fail!");
        }
    });

我也尝试过:

$("textarea#msg").val()

然后在这里用php指出:

$msg = $_POST['msg'];

它总是返回TRUE(显示为“1”)

我做错了什么?

编辑:PHP-File:

<?php
if(!isset($_POST['email']) || !isset($_POST['msg']) || !isset($_POST['phone'])){
    echo "Access denied!";
    exit;
}
$email = htmlentities($_POST['email']);
$msg = htmlentities($_POST['msg']);
$phone = htmlentities($_POST['phone']);

if($email != "" && $msg =! "" && $phone != ""){
    echo "Danke f%FCr ihre Anfrage! \n Email: $email \n Msg: $msg \n Phone: $phone";
}else{
    echo "Bitte alle Fleder ausf%FCllen!";
}

&GT;

1 个答案:

答案 0 :(得分:0)

试试这个, $ msg!=

<?php
    if(!isset($_POST['email']) || !isset($_POST['msg']) || !isset($_POST['phone'])){
        echo "Access denied!";
        exit;
    }
    $email = htmlentities($_POST['email']);
    $msg = htmlentities($_POST['msg']);
    $phone = htmlentities($_POST['phone']);

    if($email != "" && $msg != "" && $phone != ""){
        echo "Danke f%FCr ihre Anfrage! \n Email: $email \n Msg: $msg \n Phone: $phone";
    }else{
        echo "Bitte alle Fleder ausf%FCllen!";
    }
    ?>