HTML の一部が ajax 呼び出しの結果に置き換えられます。テスト中、私はその ajax 呼び出しを置き換えたものとまったく同じものにしました。問題は、古い html に適用した JQuery UI と「onClick」のいずれも、新しい html に適用されなかったことです。適用した関数を再度呼び出してみましたが、うまくいきません。奇妙なことに、Google Chrome のカウンセルに直接入力すると機能します (new-ajax-html は JQuery コマンドによって影響を受けます)。
これは私のコードで、最初の html の元の設定 (動作) と 2 番目の設定 (必要なすべての要素がインスタンス化された後に行われます) を含みます。
function set_up() { // <-- if I call this function in the consul, it works.
$('.delete-button').click(function() {
var confirm = window.confirm("Are you sure you want to delete? After you save, this file will not be recoverable.")
if (confirm){
$(this).parent('.deletable-group').remove()
}
});
$('.field-default[data-multi="True"]').makeMulti();
$("input.field-input-date").datepicker();
alert("HERE!") //Is reached both times I call the function. So the code above is executing.
}
var options = {
target: '.server-response-box',
success: function() { //<--- Gets called when the ajax call goes through.
$('.needs-update').each(function( index ) {
url = "/field/1/" + $('.edit-wrapper').attr('data-entry-ID') + "/" + $(this).attr('data-field-id');
old_this = this
$.get(url,function(data){
$(old_this).replaceWith(data);
});
});
set_up(); // Tries to set everything up again.
},
beforeSubmit: function(arr, $form, options) {
}
};
$('#form').ajaxForm(options);
set_up(); //<-- sets it all up the first time.