Javascript 在对话框上显示值
我正在动态创建一个对话框。我想在对话框上打印从spring控制器收到的作为响应的动态值。 作为$(document).ready(函数()首先加载),我无法在对话框中显示动态值 下面是我尝试的代码:Javascript 在对话框上显示值,javascript,jquery,html,jsp,Javascript,Jquery,Html,Jsp,我正在动态创建一个对话框。我想在对话框上打印从spring控制器收到的作为响应的动态值。 作为$(document).ready(函数()首先加载),我无法在对话框中显示动态值 下面是我尝试的代码: var $dialog; var dynamicValue; var contextPath = "<%=request.getContextPath()%>"; $(document).ready(function () { $dialog =
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$对话框;
var动态价值;
var contextPath=“”;
$(文档).ready(函数(){
$dialog=$('')
.html(“”+dynamicValue+“”)
.对话({
自动打开:错误,
宽度:“400”,
身高:300,
莫代尔:是的,
按钮:{
“关闭”:函数(){
$(此).dialog(“关闭”);
}
}
});
});
函数showDialog()
{
var-xmlHttp;
if(window.XMLHttpRequest)
{
xmlHttp=新的XMLHttpRequest();
}
else if(window.ActiveXObject)
{
xmlHttp=新的ActiveXObject(“Microsoft.xmlHttp”);
}
var url=contextPath+“/aboutATM.htm”;
xmlHttp.onreadystatechange=函数(){
handleServerResponse(xmlHttp);
};
open(“GET”,url,true);
xmlHttp.send(空);
函数handleServerResponse(xmlHttp)
{
if(xmlHttp.readyState==4 | | xmlHttp.readyState==complete)
{
$dialog.dialog('open');
$dialog.dialog(“选项”、“标题”、“加载…”)。dialog(“打开”);
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>')
}
}
}
var$对话框;
var动态价值;
var contextPath=“”;
$(文档).ready(函数(){
$dialog=$('')
.对话({
自动打开:错误,
宽度:“400”,
身高:300,
莫代尔:是的,
按钮:{
“关闭”:函数(){
$(此).dialog(“关闭”);
}
}
});
});
函数showDialog()
{
var-xmlHttp;
if(window.XMLHttpRequest)
{
xmlHttp=新的XMLHttpRequest();
}
else if(window.ActiveXObject)
{
xmlHttp=新的ActiveXObject(“Microsoft.xmlHttp”);
}
var url=contextPath+“/aboutATM.htm”;
xmlHttp.onreadystatechange=函数(){
handleServerResponse(xmlHttp);
};
open(“GET”,url,true);
xmlHttp.send(空);
函数handleServerResponse(xmlHttp)
{
if(xmlHttp.readyState==4 | | xmlHttp.readyState==complete)
{
$dialog.dialog('open');
$dialog.dialog(“选项”、“标题”、“加载…”)。dialog(“打开”);
$dialog.html(“”+xmlHttp.responseText+“”)
}
}
}
调用文档末尾的showDialog()函数!