jQueryを使用してページをリロードせずにコメントをアニメーション化したり、コメントを削除したりする私のウェブサイトにはコメント欄があります。PHPからのデータをjavascriptファイルに戻しますか?
今はコメントを書くときに外部のJSに送信し、次にPHPのファイルに送信して処理します。成功した場合は、コメントセクションにコメントを追加します。私の削除アクション:jQueryはmysqlデータベースのコメントIDを削除します。
私の問題は、jQuery経由で削除ボタンを追加し、何とかjavascriptファイルにコールバックしてidに伝えるので、削除ボタンはフォームに入れるIDを知っているので、削除ファイルは何を削除するのか分かります。 ?事前に
$(function() {
$(".commentbutton").click(function() {
$.ajax({
type: "POST",
url: "http://myflashpics.com/process_addcomment.php",
data: $("#commentform").serialize(),
success: function() {
var theComment = $("#commentsss").val();
var theUserId = $("#user_id_two").val();
var thePhotoId = $("#photo_id").val();
var theProfilePicture = $("#user_profile_picture").val();
var theUsername = $("#user_username").val();
// Get new HTML data
var html = "<div class='comment_odd'><img src='" + theProfilePicture + "' class='comment_thumbnail'/><div class='comment_username'>" + theUsername + "</div><div class='comment_text'>" + theComment + "</div></div>";
// Append, then fade in
$(html).hide().appendTo(thecommentsdisplay).fadeIn(500);
}
});
return false;
});
});
ありがとう:
は、ここに私のadd_comment
スクリプトです!
Coulton
EDIT 1:
は、ここに私のコメントフォーム(単に明確にする)です:
<form method='post' action='' name='deleteform' id='deleteform'>
<input type='hidden' name='userid' value='<?php echo "$userid_session"; ?>' />
<input type='hidden' name='userpass' value='<?php echo "$password_session"; ?>' />
<input type='hidden' name='pictureid' id='pictureid' value='<?php echo "$picture_id"; ?>' />
<input type='hidden' name='profilepictureid' id='profilepictureid' value='<?php echo "$user_profile_picture_id"; ?>' />
</form>
そして最後に、私のDELETE:
user_id_two (the user's ID)
commentsss (comments field)
photo_id (the id of the photo being commented on)
user_profile_picture (profile to display on the user's profile picture in the banner)
user_username (username of the user commenting)
はここにも私の削除ボタン形ですコメントjQuery:
$(function() {
$(".commentdeletebutton").click(function() {
var className = $(this).attr('class');
var theID = className.replace(/delete_button commentdeletebutton delete_(\d+)/, "$1");
commentDone = "#comment_" + theID;
formDone = "#commentdeleteform_" + theID;
$.ajax({
type: "POST",
url: "http://myflashpics.com/process_deletecomment.php",
data: $(formDone).serialize(),
success: function() {
$(commentDone).hide();
}
});
return false;
});
});
:
は、より完全なサンプルのために編集されました。最初に、いくつかのIDがありますが、あなたは私たちに設定/使用していないことを示しています。第二に、あなたのコードはすべて匹敵しないし、混乱します。 – Christian
私の更新を確認してください。 – iosfreak
なぜフォーム全体を削除する必要があるのか分かりませんが、単純なリンクではないのはなぜですか? – morgar