Sie Ajax verwenden könnten die HTML aus dem 2. jsp zu bekommen und dann auf das DOM oder zum innerHTML- eines Elements hängen.
Haupt 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 >
Musterseite mit Code bestätigen -> jede gültige html für die div könnte confirm.jsp Aktion Do ... Sind Sie sicher?
// todo Form hier html der Spanne/Pop-up/script/css -> wie ein iframe
Sieht aus wie Sie eine Bestätigung angezeigt werden soll - einige UI fragen tun Sie wirklich abmelden wollen?
Der beste Weg für das wäre eine leere Spanne mit der ID „logoutConfirmSpan“ dann auf Klick auf Logout zu machen, gehen Sie wie Ajax (asynchroner Modus -> false, so dass es inline geschieht), um die HTML-Markup und setzen Sie es an die die Innerhtml der Spanne
Das HTML sollte so gültig sein, dass es die Benutzeroberfläche erscheinen und das Formular wirklich abmelden.
See Replace inner HTML of a div with Ajax response sagt Ihnen, wie Ajax verwenden, um mit jQuery
Einfache Beispiel:
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>
also, sind Sie auf einen Fehler gestoßen? –
no. Ich bekomme keinen Fehler. Die Seite wird nicht geladen – mukund
versuchen, in JavaScript-Konsole einchecken. –