2014-09-29 64 views
0

我正在动态创建一个对话框。我想要打印动态值,这是我从对话框中的弹簧控制器接收到的响应。 作为$(文件)。就绪(函数()首先加载我能不能够显示在对话框中动态值在对话框中显示值

下面是我试过的代码:。

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; 
      } 
     } 
    } 
+0

调用函数showDialog()在文档的末尾准备就绪! – binboavetonik 2014-09-29 16:51:11

回答

1

少许修改它将为你工作..

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>') 
      } 
     } 
    }