gpt4 book ai didi

jQuery ajax 帖子被触发两次

转载 作者:行者123 更新时间:2023-12-01 05:05:06 26 4
gpt4 key购买 nike

我正在使用 jquery 对页面执行 $.post ,问题是该帖子在触发时执行了两次,我尝试在 IE 和 Firefox 中运行该页面,结果是相同的,并使用firebug显示该请求被bieng提交了两次。

我需要您的帮助,提前致谢。这是代码:

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 的标题: 响应头日期 2011 年 7 月 9 日,星期六 13:29:51 GMT服务器 Apache/2.2.17 (Win32) PHP/5.3.5X-Powered-By PHP/5.3.5截止时间 1981 年 11 月 19 日星期四 08:52:00 GMT缓存控制无存储、无缓存、必须重新验证、后检查=0、预检查=0Pragma 无缓存内容长度 24保持事件超时=5,最大值=84连接保持事件状态内容类型 text/html请求 header 主机127.0.0.1:8888用户代理 Mozilla/5.0(Windows NT 6.1;rv:2.0.1) Gecko/20100101 Firefox/4.0.1接受 application/json、text/javascript、/; q=0.01接受语言 en-us,en;q=0.5接受编码 gzip、deflate接受字符集 ISO-8859-1,utf-8;q=0.7,*;q=0.7保持活力 115连接保持事件状态内容类型 application/x-www-form-urlencoded;字符集=UTF-8X-请求-使用 XMLHttpRequest推荐人 http://127.0.0.1:8888/Lightc-tables/msgs.php内容长度41Cookie PHPSESSID=ku8e6o3h2bl27ltofkir58a626

并且具有不同过期时间的相同 header 也在该 header 之后重复。

最佳答案

你需要使用一些小的trigger-hoak;)

$(".ticketbutton").unbind("click");
$(".ticketbutton").unbind("live");
$(".ticketbutton").die();

关于jQuery ajax 帖子被触发两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6631977/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com