textarea的jquery值

时间:2010-04-21 10:20:35

标签: jquery ajax

我有下面的代码,它发送textarea的值并获得失败或成功响应,现在我只检查它是否显示“hello”。

function postdata()
{
    $.ajax({
    type: "POST",
    dataType: "text",
    url: "makepost.php",
    data: "post_text=" + $("#post_text").val(),
    cache: false,
    success: function(reply_text)
    {
        if (reply_text.indexOf("Successful") >= 0)
        {
            alert("Post Made");     

        }
        else 
        {
            alert(reply_text);
        }
    }
    });
}

<textarea rows="3" cols="25" id="post_text" ></textarea><br />
    <input type="submit"  id="post_bttn" value="Post" onclick="postdata(); return false;">

我还测试了只是回显了textarea的值,并且它总是空白。虽然在萤火虫中它表明我已发送该文本。

有什么想法吗?谢谢:))

编辑:添加了php代码

<?php

$post=$_GET['post_text'];

if ($post=="hello")
{
    echo "Successful";
    return 1;
}
else
{
    echo $post;
    return 0;

}

?>

2 个答案:

答案 0 :(得分:4)

您的AJAX正在使用POST,而PHP正在寻找GET

答案 1 :(得分:1)

尝试使用$("#post_text").html()