jQuery를 사용하여 페이지를 다시로드하거나 주석을 삭제하지 않고도 주석을 적용하는 웹 사이트의 주석 섹션이 있습니다.PHP에서 데이터를 다시 자바 스크립트 파일로 반환 하시겠습니까?
지금 당장은 주석을 작성하면 외부 JS로 보낸 다음 PHP가 처리하는 PHP 파일로 보냅니다. 성공한 경우 댓글 섹션에 댓글을 추가합니다. 내 삭제 작업 : jQuery는 mysql 데이터베이스에서 내 코멘트 ID를 삭제합니다.
그래서 내 문제는 jQuery를 통해 삭제 버튼을 추가하고 어떻게 든 자바 스크립트 파일을 다시 호출하여 삭제 버튼이 삭제할 파일을 알 수 있도록 삭제 버튼이 양식에 넣을 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
편집 1 : 여기
내 의견 양식이다 (단지 명확하게) :
여기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)
의도 내 삭제 버튼 형태 : 마지막으로
<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 COMMENT 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