0
你好,我想問我怎麼可以從Javascript後發佈HTML打印$ POST值?
這裏是我的HTML提交形式:
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="./comments.js"></script>
</head>
<div id="addCommentContainer">
<form class="add-comment-form" id="addCommentForm3" method="post" action="">
<input type="hidden" value="3" name="comentonpost" id="comentonpost" />
<textarea class="commentinput" name="body" id="body" cols="20" rows="5"></textarea>
<input type="button" class="add-comment-submit" value="Submit" />
</form>
</div>
<div id="addCommentContainer">
<form class="add-comment-form" id="addCommentForm3" method="post" action="">
<input type="hidden" value="3" name="comentonpost" id="comentonpost" />
<textarea class="commentinput" name="body" id="body" cols="20" rows="5"></textarea>
<input type="button" class="add-comment-submit" value="Submit" />
</form>
</div>
這裏是我的javascript:
$(document).ready(function() {
$(".add-comment-submit").on("click", function (e) {
e.preventDefault();
var submit = $(this);
if (submit.hasClass("working")) return false;
submit.addClass("working");
submit.val("Working...");
$.post('submit.php',$(this).serialize(),function(msg){
submit.removeClass("working");
submit.val("Submit");
$("<div></div>").html(msg).fadeIn("slow").insertBefore(submit.parent($(".addCommentContainer"))).slideDown();
});
});
});
這是我submit.php正在打印的 「Hello World」 提交後:
<?PHP
$message = 'Hello World';
echo $message;
?>
我不知道爲什麼,但現在看來,這不是張貼在submit.php的信息還是我在錯誤的地方,因爲當我嘗試這submit.php:
<?PHP
$message = $_POST["body"];
echo $message;
?>
這不是印刷是什麼在名稱爲「body」的文本區域中鍵入。我如何讓它打印什麼是寫在身體輸入文本區域?
在此先感謝!
你的ids應該是唯一的一個頁面..爲什麼你重複相同的形式兩次? – swapnesh
因爲我有許多形式,它必須被提交併且只在提交表單之前發佈結果。 –
在你的'submit.php'中,print_r($ _ POST)是什麼;'print? – MaX