我正在嘗試使用ajax插入註釋。一切工作正常,除了$ _POST。它似乎沒有發佈數據,所以表中的註釋字段爲空。其他事情工作正常,如插入日期。我只有ajax問題(在php中沒有問題)。
總之,這裏是我的代碼: -ajax發佈數據並插入數據庫
<head>
<script>
function su_post(id) {
$("#load_post").show(),
$("#post_submit").click(function() {
var c_post = $("#c_post").val();
var dataString = '&c_post=' + c_post;
$.ajax({
type: "POST",
url: '/script/post.php',
data: "id=post_script" + id,
cache: false,
success: function(){
$("#load_post").fadeOut();
}
})});
};
</script>
</head>
<body>
<form id="form_post" method="post" action="javascript:su_post(1)">
<label for="c_post">Post your updates/status</label>
<input type="text" name="c_post" id="c_post" />
<br /><br /><input type="submit" id="post_submit" value="Post" />
</form>
</body>
編輯:既然你可能沒有明白我的意思;在獲取您在輸入框中輸入的值並將值發佈或發送到post.php時存在問題。當我把data: {id: post_script + id, c_post: c_post}
,它的代碼似乎並沒有加載php文件。 (卡上發帖 - >http://prntscr.com/10dmjt)
預先感謝您:)
你是什麼'rand'場的作用?如果你放棄它會發生什麼?爲什麼'append'聲明被註釋掉了? – Floris
對不起,我不打算髮布該行。我已經評論過,所以我會記住它,當我需要它 –