我有一个灯箱形式在框中工作的新条目添加到我datatable形式与此代码:防止多个Ajax查询
$(“#add-quotation”).click(function(event) {
event.preventDefault();
var customer_id = $(this).attr(‘data-customer’);
$.nmManual(
‘#quotation_manage’,{
sizes: { // Size information
w: 500, // Initial width
h: 500 // Initial height
}
});
$(‘#quotation_submit’).live(‘click’, function(event){
event.preventDefault();
if(typeof($.nmTop()) != “undefined”){
$.nmTop().close();
}
var loading = $(‘.loading-notification’);
loading.removeClass(‘hidden’);
var date = $(‘#date_activate’).val();
var budget = $(‘#budget’).val();
var hospital = [$(‘#hospital’).val(), $(‘#hospital option:selected’).text()];
var dental = [$(‘#hospital’).val(), $(‘#hospital option:selected’).text()];
var optical = [$(‘#optical’).val(), $(‘#optical option:selected’).text()];
var doctor = [$(‘#doctor’).val(), $(‘#doctor option:selected’).text()];
$.ajax({
type: ‘POST’,
data: ‘create=true&customer_id=’ + customer_id + ‘&date=’ + date + ‘&budget=’ + budget + ‘&hospital=’ + hospital[0] + ‘&dental=’ + dental[0] + ‘&optical=’ + optical[0] + ‘&doctor=’ + doctor[0],
url: ‘quotation.php’,
dataType: ‘json’,
async: false,
success: function(result){
if (result){
oTable.fnAddData([
result.id,
result.date,
budget,
hospital[1],
dental[1],
optical[1],
doctor[1],
”,
”,
”,
‘test’
]);
}
loading.addClass(‘hidden’);
}
});
});
});
它工作得很好,但有时它发送3个或更多的查询,我怎样才能防止这个?通常它应该只发送一个查询。
2011-12-12
Awea
+0
是该事件’$( “#附加报价”)。单击(”中创建的document.ready()’?有的时候’click’事件创建的多个时间代码和你确实有这种行为 –
+0
它创建在页面末尾 –