储户。你就像裂缝一样。当我需要修复时,我会来找你... 我有一个用户提交的评论系统,它使用 jQuery 对话框在用户提交表单之前确认内容。
第一次绕行没问题。对话框触发良好并且表单提交。当我再次尝试发布时,ajax 调用失败,对话框没有触发,并且提交了默认表单。
该对话框绑定在表单的成功 ajax 创建中,所以据我所知,它应该是绑定的,但我肯定遗漏了一些东西。
这是代码。
第一个 ajax 调用引入了一个表单来发布评论。成功加载后,我会在用户尝试提交表单时启动要调用的对话框。
// Make the ajax call for the apppropriate content.
$.ajax({
type: 'Get',
url: 'a/url/to/process/form',
cache: false,
beforeSend: function() {
},
success: function(data) {
$('#commentBox_' + id).html(data).fadeTo('fast', 100);
$('#' + oId).addClass('remove').removeClass('respond').html('Close');
// Destroy the instance if it has already been called.
if(CKEDITOR.instances['comment'])
{
delete CKEDITOR.instances['comment'];
}
$('#discussionComment_' + id).submit(function() {
CKupdate()
});
// Set the editor.
CKEDITOR.replace('comment', {toolbar : 'Basic', skin : 'Office2003', height : 250})
// Set the submit option.
$('#postComment_' + id).live('click', function() {
// Warn the user about submitting. Let them review their comment.
CKupdate() // Update the field with user input content.
$('.ui-dialog-content').dialog("destroy"); // Get rid of any old dialogs lurking around.
// Get the content from the form for the confirmation dialog
var commentTitle = $('#commentSubject_' + id).val();
var commentBody = CKEDITOR.instances['comment_' + id].getData();
// Build the new dialog.
var NewDialog = $('<div>You are about to submit your comment. Verify before submitting.<hr /><h4>' + commentTitle + '</h4><div>' + commentBody + '</div></div>');
$(NewDialog).dialog({
modal: true,
title: 'Confirm Post',
width: 500,
buttons: {
'Submit': function() {
commentPost_ajax(id); // Post the form via ajax.
$(this).dialog('destroy');
},
'Edit': function() {
$(this).dialog('destroy');
return false; // Don't submit the form.
}
}
});
return false;
});// Click to submit form.
},
error: function() {
window.location = "../../post_discussionComment.html?dId<%=dId%>&id=" + id
}
});
// Stay here. We're just starting to have fun.
return false;
这是 ajax 帖子的功能。
function commentPost_ajax(id) {
// Just close and submit.
$('#discussionComment_' + id).ajaxSubmit({
beforeSend: function() {
$('#discussionComment_' + id + ' input:submit').html('Sending...');
$('#newEntry').attr('id', '');
},
success: function(data) {
$('#commentBox_' + id).after(data);
$('#discussionComment_' + id).remove();
$('#discussionComment_' + id).hide('puff', function() { $(this).remove() }, 'fast');
$('#content_' + id + ' a.remove').removeClass('remove').addClass('respond').html('Respond');
$('.expand').show();
window.location + $('#newEntry');
$('#newEntry').children().effect("highlight", {}, 3000);
},
error: function () {
alert('There was a problem posting your comment. Please try again.');
}
}); // Form submit
}
任何帮助,将不胜感激。我仔细阅读了很多其他问题,但没有一个直接谈到这一点。如果他们这样做了,我找不到他们。