我有下面的代码,它发送文本区域的值并获得失败或成功响应,现在我只检查它是否显示“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;">
我还测试了仅回显文本区域的值,并且它始终是空白的。尽管在 firebug 中它显示我已经发送了该文本。
有什么想法吗?谢谢:)
编辑:添加 php 代码
<?php
$post=$_GET['post_text'];
if ($post=="hello")
{
echo "Successful";
return 1;
}
else
{
echo $post;
return 0;
}
?>
最佳答案
您的 AJAX 正在使用 POST
,而 PHP 正在寻找 GET
。
关于jquery 文本区域的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2682011/