1
我有一张表格,列出了每条记录的名称,属性和注释。我希望能够在工具提示中显示评论,并且能够通过Ajax更新这些评论。我想通过点击链接来显示工具提示或模式。这个模式将会有一个textarea,并且预装了注释。用户可以修改注释并通过Ajax将其提交给操作页面。成功提交后,现有的工具提示内容也需要更新。qTip2中的Ajax表单
任何帮助将不胜感激。
我正在使用qtip2和醉酒插件。
我正在通过ajax在qTip2工具提示onclick中加载表单。表单的链接从rel标签中移除。现在,当我提交表单时,它不会通过ajax提交,而是直接提交操作页面。这是我的JS代码:
$('.commentsedit').each(function()
{
// We make use of the .each() loop to gain access to each element via the "this" keyword...
$(this).qtip(
{
content: {
// Set the text to an image HTML string with the correct src URL to the loading image you want to use
text: '<img class="throbber" src="images/throbber.gif" alt="Loading..." />',
ajax: {
url: $(this).attr('rel') // Use the rel attribute of each element for the url to load
},
title: {
text: $(this).attr('title'), // Give the tooltip a title using each elements text
button: true
}
},
position: {
at: 'bottom center', // Position the tooltip above the link
my: 'top right',
viewport: $(window), // Keep the tooltip on-screen at all times
effect: false // Disable positioning animation
},
show: {
event: 'click',
solo: true // Only show one tooltip at a time
},
hide: 'unfocus',
style: {
classes: 'my_width_setting_class qtip-wiki qtip-light qtip-shadow'
},
events: {
render: function(event, api) {
// Capture the form submission
$('form', this).bind('submit', function(event) {
// Grab and store input elements
var inputs = $(':textarea', this);
// Common ajax error handler
function errorHandler(jqXHR, message) {
// Set the error and show/hide it
$('.error', api.elements.tooltip).html(message || '').toggle(!!message);
}
// Setup AJAX request
$.ajax({
url: 'commentsform.cfm',
data: $(this).serialize(),
type: 'post',
dataType: 'json',
success: function(data, status, jqXHR) {
// On success, show message and refresh after 2 seconds
if(data.status === 'success'){
api.set('content.text', data.message + ' Redirecting...');
setTimeout(function(){ window.location.reload() }, 2000);
}
// Call error handler on error status too.
else { errorHandler(jqXHR, data.message); }
},
error: errorHandler,
// Disable/Enable input elements
beforeSend: function() { inputs.attr('disabled', 'disabled'); },
complete: function() { inputs.removeAttr('disabled'); inputs[0].focus(); }
});
// Prevent normal form submission
event.preventDefault();
});
}
}
})
})
尽管此链接可能回答问题,最好包括答案的基本部分[这里](http:// meta .stackoverf low.com/a/8259)并提供供参考的链接。如果链接页面更改,则仅链接答案可能会失效。 – bummi 2014-05-06 14:01:40
完全同意。我会尽快编辑。非常感谢您指出。 – 2014-05-06 14:06:16