2014-09-29 65 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>') 
      } 
     } 
    }