jquery value of textarea
I have the code below, which sends the value of the textarea and either gets a fail or Successful response, for now I just check if it says "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="post开发者_运维问答data(); return false;">
I have also tested just echo'ing out the value of the textarea, and all the time it is jus blank. Although in firebug it shows that I have sent that text.
Any ideas? Thanks :)
edit : added php code
<?php
$post=$_GET['post_text'];
if ($post=="hello")
{
echo "Successful";
return 1;
}
else
{
echo $post;
return 0;
}
?>
Your AJAX is using POST
, while PHP is looking for GET
.
Try $("#post_text").html()
instead
精彩评论