关闭并重新打开弹出窗口时,客户端无数次呼叫服务器

时间:2019-02-01 16:05:07

标签: javascript http server request client

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

这是在我们第一次打开弹出窗口并进行第一次过滤之后,您可以看到有两个对NarrowEventsSearch的请求 first try

下图显示了关闭弹出窗口后再次打开并在其中进行过滤后会发生的情况。我们可以看到,现在有3个针对NarrowEventsSearch的请求已发送 second try

这是打开弹出窗口的js代码 enter image description here

被调用的函数如下

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();    

0 个答案:

没有答案