首页 > 解决方案 > 当我关闭并重新打开弹出窗口时,客户端无数次调用服务器

问题描述

我有一个用 Javascript 打开的弹出窗口。在这个弹出窗口中,我有一个用于过滤的面板。每次用户单击过滤器上的选项并更新结果时,都会向服务器发送一个请求。但是,如果我关闭弹出窗口并重新打开它并再次使用过滤器,请求将被发送两次,如果我继续重复相同的步骤序列,我将继续将每次发送的请求增加 1。

这是在我们第一次打开弹出窗口并第一次过滤之后,您可以看到 NarrowEventsSearch 有两个请求 第一次尝试

下图显示了在我关闭弹出窗口重新打开它并在其中过滤后会发生什么。我们可以看到现在为 NarrowEventsSearch 发送了 3 个请求 第二次尝试

这是打开弹窗的js代码 在此处输入图像描述

被调用的函数如下

function tb_show(fake_param, url, callbackFunction) {
SetAjaxCaching(false);
var params = parseThickBoxArgs(url);
trace("----------- Thickbox parameters -----------");
trace("URL Passed was " + url);
trace(params);

var href = params["url"] + "?" + $.param(params);
var dialogTitle = $(this).attr("title");

//Unique id is given for the div
var divId = new Date().getTime().toString();
// Create an anonymous div with a loading gif to be the dialog
var newDiv = $('<div id="' + divId + '"  class="dialogcontainer">' + spinnerHTML + '</div>');

// We push the newly created div onto the window stack so we can keep track of what dialogs are open
window.openedDialogs.push([newDiv, href]);
$('body').append(newDiv);

trace("Opening dialog with height " + params["height"] + " and width " + params["width"]);
//To avoid the scrollbars.
var height = parseInt(params["height"]) + 10;
var width = parseInt(params["width"]) + 10;

if (params["percentWidth"] !== undefined) {
    var windowWidth = $(window).width();
    var percentWidth = parseFloat(params["percentWidth"]) / 100.0;

    width = windowWidth * percentWidth;
}
if (params["percentHeight"] !== undefined) {
    var windowHeight = $(window).height();
    var percentHeight = parseFloat(params["percentHeight"]) / 100.0;

    height = windowHeight * percentHeight;
}

var CssClass = params["class"];
if (CssClass == undefined) {
    CssClass = '';
}

var title = params["title"];

// Now we actually invoke the dialog function with the parameters we parsed earlier
newDiv.dialog({
    title: title,
    height: height, //params["height"],
    width: width, //params["width"],
    closeOnEscape: false,
    modal: true,
    open: function (event, ui) {
        $(this).parent().find('.ui-dialog-titlebar').append("<div style=\"float: right;\"><img src=\"/Resources/Content/Images/Icons/remove.png\" class=\"Delete\" style=\"cursor: pointer;\" onclick=\"closeDialog('" + CssClass + "')\" /></div>");
    }
})
    .load(href, JSON.stringify({ showLoadingBar: false }), function () {
        trace("Overlay Div content loaded");
        // After the content has been loaded, apply the thickbox script to the loaded content
        applyThickboxes($(this));
        // Now run the callback function, if it is indeed a function
        if (typeof (callbackFunction) == 'function') {
            callbackFunction();
        }
    });
hideTitleBar();
//LoadValidation();    

标签: javascripthttpserverrequestclient

解决方案


推荐阅读