繁体   English   中英

在对话框上显示值

[英]show value on the dialog box

我正在动态创建一个对话框,我想在对话框上打印我作为弹簧控制器的响应收到的动态值。 由于$(document).ready(function()首先加载,我无法在对话框上显示动态值。

下面是我尝试的代码:

    var $dialog; 
var dynamicValue;
    var contextPath = "<%=request.getContextPath()%>";
    $(document).ready(function () {
        $dialog = $('<div></div>')
           .html('<table><tr><td>' + dynamicValue + '</td></tr></table>')
          .dialog({
            autoOpen: false,
            width:"400",
            height:300,
            modal: true,
            buttons: {
                "Close": function() {
                    $(this).dialog("close");
                }
            }
        });
    });


    function showDialog()
    {
        var xmlHttp;  
        if (window.XMLHttpRequest)
        {
            xmlHttp= new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
        }
        var url = contextPath+"/aboutATM.htm";
        xmlHttp.onreadystatechange = function() {
            handleServerResponse(xmlHttp);
        };
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);

        function handleServerResponse(xmlHttp)
        {   
           if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
           {
             $dialog.dialog('open');
             $dialog.dialog("option", "title", "Loading....").dialog("open"); 
          dynamicValue = xmlHttp.responseText;
           }   
        }
    }

修改了一下。 它将为您工作。

 var $dialog; 
 var dynamicValue;
    var contextPath = "<%=request.getContextPath()%>";
    $(document).ready(function () {
        $dialog = $('<div></div>')
          .dialog({
            autoOpen: false,
            width:"400",
            height:300,
            modal: true,
            buttons: {
                "Close": function() {
                    $(this).dialog("close");
                }
            }
        });
    });


    function showDialog()
    {
        var xmlHttp;  
        if (window.XMLHttpRequest)
        {
            xmlHttp= new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
        }
        var url = contextPath+"/aboutATM.htm";
        xmlHttp.onreadystatechange = function() {
            handleServerResponse(xmlHttp);
        };
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);

        function handleServerResponse(xmlHttp)
        {   
           if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
           {
             $dialog.dialog('open');
             $dialog.dialog("option", "title", "Loading....").dialog("open"); 
             $dialog.html('<table><tr><td>' + xmlHttp.responseText + '</td></tr></table>')
           }   
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM