你可以使用AJAX来从第二JSP在HTML,然后附加到DOM或一个元素的innerHTML。
主要Page.jsp与确认码
<span id=confirmSpan></span>
<script language="Javascript">
function xmlhttpPost(strURL, queryStr) {
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari, opera etc
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}else{
alert("no ajax")
return
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
updatepageConfirm(self.xmlHttpReq.responseText);
}
}
self.xmlHttpReq.send(queryStr);
}
function updatepageConfirm(str){
document.getElementById("confirmSpan").innerHTML = str;
}
function logout1(){
xmlhttpPost("confirm.html");//http://sel2in.com/pages/prog/html/ajax/confirm.html", "")
}
</script>
</head>
<body>
<form id="search" action="/search" method="get">
<input type=button onclick=logout1() value=logout>
</form >
样品页面 - >为DIV任何有效的HTML可能是 confirm.jsp 做动作......你确定吗?跨度
// TODO形式在这里 HTML /弹出/脚本/ CSS - >就像一个iframe
看起来要显示一个确认 - 一些用户界面问你是否真的要退出?最好的方法是创建一个id为“logoutConfirmSpan”的空跨度,然后点击注销,做ajax(异步模式 - > false,所以它发生内联)获取html标记并将其设置为innerHTML的跨度
该html应该是有效的,这样它会使用户界面显示并且形式才能真正注销。
见Replace inner HTML of a div with Ajax response告诉你如何使用Ajax与jQuery
简单的例子:
HTML snippets
<span id = 'logoutConfirmSpan'> </span>
<script>
// call ajax, with the response call setHtmlForConfirm
function setHtmlForConfirm(req)
{
document.getElementById('logoutConfirmSpan').innerHTML = req.responseText;
}
//req.responseText should have the html to show the confirm UI and form to submit yes/ no
</script>
那么,你有没有遇到任何错误? – 2013-04-23 07:18:50
没有。我没有得到任何错误。页面没有得到加载 – mukund 2013-04-23 07:19:47
尝试检查在JavaScript控制台。 – 2013-04-23 07:20:15