0
我正在使用drupal的网站。我写了自定义模块,它在浏览器中显示通知,并在网站中打开弹出窗口。使用ajax制作网站缓慢或mysql锁定显示通知并打开网站弹出框
如果条件为错误或错误发生,我正在使用JavaScript函数,该函数每15秒或更少时间调用一次。
问题是如果有5个页面打开,那么在所有页面上设置超时功能在所有页面上每15秒钟或更短时间呼叫并使站点变慢或破坏站点。
请提供一些指导来改善本网站的性能。
(function ($) {
$(function() {
// 任何需è¦æ‰§è¡Œçš„js特效
setTimeout("countSecond2()", 15000);
$('body').on('click','#popClose',function(event){
//jQuery(".pop_content_message").click(function() {
$(this).parents('#pop').remove();
});
});
})(jQuery);
function countSecond() {
var data = '';
var need_delay = 0;
var js_common_messages_popup = '/messages/popup';
jQuery.ajax({
url: js_common_messages_popup,
type : "post",
dataType : "text",
data : data,
async: true,
success: function(msg) {
var Obdata = jQuery.parseJSON(msg);
if(Obdata !=null){
//alert('1p='+JSON.stringify(msg));
var call = Obdata.call;
var output = Obdata.output;
var selectbox = Obdata.selectbox;
var checkbox = Obdata.checkbox;
var url = Obdata.url;
var need_delay = Obdata.need_delay;
if (call == '1') {
browser_notification(Drupal.t('You have a new reminder'), '', url);
jQuery('#id_pop_task').prepend(output);
jQuery('#id_pop_task .pop_content_message').show();
/*jQuery('#id_pop_task').html(output);
jQuery('#pop').show();
jQuery("#popClose").click(function() {
jQuery('#pop').hide();
});*/
if (selectbox == '1') {
//jQuery("#antiStress").selectbox();
jQuery("[id=antiStress]").selectbox();
}
if (checkbox == '1') {
jQuery('.customR input[type="checkbox"]').ezMark({checkboxCls: "ez-checkbox-green", checkedCls: "ez-checked-green"});
}
setTimeout("countSecond2()", 15000);
}else {
countSecond2();
}
}
else {
countSecond2();
}
},
beforeSend: function() {
//jQuery('#loading').hide();
},
complete: function() {
},
error: function() {
countSecond2();
//location.reload();
}
});
}
function countSecond2() {
var data = '';
var need_delay = 0;
var js_common_messages_popup = '/messages/popup2';
jQuery.ajax({
url: js_common_messages_popup,
type : "post",
dataType : "text",
data : data,
async: true,
success: function(msg) {
var Obdata = jQuery.parseJSON(msg);
if(Obdata !=null){
//alert('2p='+JSON.stringify(msg));
var call = Obdata.call;
var output = Obdata.output;
var selectbox = Obdata.selectbox;
var checkbox = Obdata.checkbox;
var url = Obdata.url;
var need_delay = Obdata.need_delay;
if (call == '1') {
browser_notification(Drupal.t('You have a new reminder'), '', url);
jQuery('#id_pop_task').prepend(output);
jQuery('#id_pop_task .pop_content_message').show();
/*jQuery('#id_pop_task').html(output);
jQuery('#pop').show();
jQuery("#popClose").click(function() {
jQuery('#pop').hide();
});*/
if (selectbox == '1') {
//jQuery("#antiStress").selectbox();
jQuery("[id=antiStress]").selectbox();
}
if (checkbox == '1') {
jQuery('.customR input[type="checkbox"]').ezMark({checkboxCls: "ez-checkbox-green", checkedCls: "ez-checked-green"});
}
setTimeout("countSecond2()", 15000);
}else {
countSecond();
}
}
else {
countSecond();
}
},
beforeSend: function() {
//jQuery('#loading').hide();
},
complete: function() {
},
error: function() {
countSecond();
//location.reload();
}
});
}
感谢您的答复:有关检测这里提供的活动标签
更多信息。我检查 –
不客气 –
但是,如果通知可用,我已经通知所有时间。所以,如果我使用这个代码,那么它将不会一直调用Ajax函数。并且通知不会按时显示。 –