だから私は$.post()
SQLiteデータベースにアクセスするphpスクリプトから返されるいくつかのhtmlコードを取得するためにを実行しています
ページが新しいhtmlをロードしたときに表示される編集ボタンにクリックイベントを添付する必要があるため、その後にクリックイベントを添付すると.empty().html()
、ユーザーがデータを送信してレコードを編集すると、別$.post()
の方法で画面が再表示され、新しいデータなので、クリックイベントハンドラーを再度アタッチします。これを行わないと、 `.click()'が最初にアタッチされたときにボタンがなかったため、ページの編集ボタンが機能しなくなります。
しかし、これを実行して複数のレコードを編集すると、複数回実行されます(実行するたびにレコードIDに警告し、$.post()
クリックした編集と同じ回数実行します。.live()
この問題の原因についての投稿を確認しました。人々は私がしていることであるバインディングクリックを提案しているので、何が起こっているのかわかりません...ここにコードがあります
$(".edit").click(function(e){
e.preventDefault();
$realTipID=this.id;
$.post("ajax.php",{action:'getTip',tipID:$realTipID},function(data){
$("#editTip_div").css("display","block");
$("#editText").empty().val(unEscapeSpecialChars(data));//puts the data that is currently in the DB into a textarea to be editted
$("#edit_tip").click(function(e){
$.post("ajax.php",{action:'editTip',tipID:$realTipID,editText:escapeSpecialChars($("#editText").val())},function(data){
if (data=="1") {//check tosee that the update of the SQL table worked
e.preventDefault();//tried this because someone suggested it in another StackOverflow post
$(".edit").unbind('click');//and this
$realTipID='';
$("#editText").val('');
$("#editTip_div").css("display","none");
$('.result[id|='+$issueID+']').click();//refreshes the <div> with the content, includes this $(".edit").click() event
if (data=="0") {//or failed
alert("record not written, could be that there are quotes in the text, please remove, quotes, apostraphes, and ticks (`) as they will cause the line to fail");
}
});
});
$("#cancel_edit").click(function() {
$("#editText").val('');
$("#editTip_div").css("display","none");
});
});
});