我正在使用jquery对页面执行$ .post,问题是这个帖子在被解雇时执行了两次,我试图在IE和firefox中运行页面,结果是一样的,并且使用萤火虫表明该请求已经提交了两次。
我需要你的帮助,提前谢谢。 这是代码:
jQuery().ready(function() {
//Reply buttons binding live event
$(".ticketButton").live('click', function(e) {
e.preventDefault();
//build dialog with id & title
$( "#msgs-form:ui-dialog" ).dialog( "destroy" );
var ticket_ID= $(this).attr("title");
var ticket_title= $(this).attr("msgTitle");
$("#msgs-dialog").attr("title", ticket_title);
//fetch data from the server to fill dialog content
$.post("server_processing_tickets_response.php", {'getTickets' : ticket_ID},
function(data){
var div_data;
//build div's of classes .ticket-1 and ticket-0 from the returned json object
$.each(data.tickets_data, function(i, tickets_data)
{
div_data += "<div class='ticket-0'><span>" + tickets_data.content + "</span></div>";
});
$(div_data).appendTo("#ticketsWrap");
}, "json");
$("#msgs-form #ticketID").attr("value", ticket_ID);
$( "#msgs-dialog" ).dialog({
autoOpen: false,
title: ticket_title,
height: 'auto',
width: 460,
show: "fade",
hide: "fade",
modal: true,
resizable: false,
buttons: false,
close: resetDialog()
});
$( "#msgs-dialog" ).dialog( "open" );
});
function resetDialog(){
$("#ticketsWrap").empty();
}
}
感谢您的快速回复! 这是我正在使用的完整javascript代码:
$(document).ajaxStart(function(){
$('#real-content').showLoading();
}).ajaxStop(function(){
$('#real-content').hideLoading();
});
//ajax forms submission
$(function() {
var msgs_table = $('#msgs_table').dataTable( {
"bJQueryUI": true,
"bProcessing": false,
"bServerSide": true,
"sAjaxSource": "server_processing_msgs.php",
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"aoColumns": [
{ "sWidth": "30px" },
{ "sWidth": "100px" },
{ "sWidth": "200px" },
{ "sWidth": "250px" },
{ "sWidth": "50px" }
],
"oLanguage": {
"sProcessing": "...تحميل",
"sZeroRecords": "لايوجد لديك تذاكر حالياً",
"sInfoEmpty": "",
"sInfoFiltered": "",
"sInfo": "يتم إظهار _START_ إلى _END_ من _TOTAL_ تذكرة",
"oPaginate": {
"sFirst": "البداية",
"sPrevious": "السابق",
"sNext": "التالي",
"sLast": "النهاية"
},
"sSearch": "بحث ضمن التذاكر:",
"sLengthMenu": "عرض _MENU_ تذكرة"
},
"aoColumnDefs": [{
"fnRender": function ( oObj ) {
return "<input type='button' style='padding:3px 6px;' name='ticket-ID-button' value='عرض' msgTitle='" + oObj.aData[3] + "\' title='" + oObj.aData[0] + "\' class=\"ticketButton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only\" />";
},
"aTargets": [ 0 ]}]
} );
jQuery().ready(function() {
$( "#ٍSucsessMessage" ).dialog({
autoOpen: false,
height: 'auto',
width: 300,
show: "fade",
hide: "fade",
modal: true,
resizable: false,
buttons: false,
});
$( "#ٍFailMessage" ).dialog({
autoOpen: false,
height: 'auto',
width: 300,
show: "fade",
hide: "fade",
modal: true,
resizable: false,
buttons: false,
});
//Reply buttons binding live event
$(".ticketButton").live('click', function(e) {
e.preventDefault();
//build dialog with id & title
$( "#msgs-form:ui-dialog" ).dialog( "destroy" );
var ticket_ID= $(this).attr("title");
var ticket_title= $(this).attr("msgTitle");
$("#msgs-dialog").attr("title", ticket_title);
//fetch data from the server to fill dialog content
$.post("server_processing_tickets_response.php", {'getTickets' : ticket_ID},
function(data){
var div_data;
//build div's of classes .ticket-1 and ticket-0 from the returned json object
$.each(data.tickets_data, function(i, tickets_data)
{
div_data += "<div class='ticket-0'><span>" + tickets_data.content + "</span></div>";
});
$(div_data).appendTo("#ticketsWrap");
}, "json");
$("#msgs-form #ticketID").attr("value", ticket_ID);
$( "#msgs-dialog" ).dialog({
autoOpen: false,
title: ticket_title,
height: 'auto',
width: 460,
show: "fade",
hide: "fade",
modal: true,
resizable: false,
buttons: false,
close: resetDialog()
});
$( "#msgs-dialog" ).dialog( "open" );
});
function resetDialog(){
$("#ticketsWrap").empty();
}
$( "#msgs-reply-button" ).click(function() {
$("#msgs-form").submit();
$("#msgs-dialog").dialog( "close" );
});
//reply form ajax submit
$("#msgs-form").submit(function(e){
e.preventDefault();
$.post("server_processing_tickets_response.php", $("#msgs-form").serialize(),
function(data){
if(data.valid == 'valid'){
$( "#ٍSucsessMessage" ).dialog( "open" );
setTimeout(function(){$( "#ٍSucsessMessage" ).dialog("close")},1500);
}
else if(data.valid == 'invalid')
{
$( "#FailMessagee" ).dialog( "open" );
setTimeout(function(){$( "#FailMessagee" ).dialog("close")},3000);
}
}, "json");
});
//Reply buttons in table//
它与请求标头有关吗? 这是我提交表单后从firebug获得的标题: 响应标题 Date Sat,09 Jul 2011 13:29:51 GMT 服务器Apache / 2.2.17(Win32)PHP / 5.3.5 X-Powered-By PHP / 5.3.5 Expires Thu,1981年11月19日08:52:00 GMT Cache-Control no-store,no-cache,must-revalidate,post-check = 0,pre-check = 0 Pragma no-cache 内容长度24 保持活动超时= 5,最大值= 84 连接保持活跃 内容类型文本/ html 请求标题 主持人127.0.0.1:8888 User-Agent Mozilla / 5.0(Windows NT 6.1; rv:2.0.1)Gecko / 20100101 Firefox / 4.0.1 接受application / json,text / javascript, / ; Q = 0.01 Accept-Language en-us,en; q = 0.5 Accept-Encoding gzip,deflate Accept-Charset ISO-8859-1,utf-8; q = 0.7,*; q = 0.7 保持活力115 连接保持活着 Content-Type application / x-www-form-urlencoded;字符集= UTF-8 X-Requested-With XMLHttpRequest 参考者http://127.0.0.1:8888/Lightc-tables/msgs.php 内容长度41 Cookie PHPSESSID = ku8e6o3h2bl27ltofkir58a626
并且在此标题之后也重复了具有不同Expires的相同标题..
答案 0 :(得分:1)
你需要使用一些小触发器;)
$(".ticketbutton").unbind("click");
$(".ticketbutton").unbind("live");
$(".ticketbutton").die();