Ajax当中如何回传一个JSP?

4.PassBackJsp
例 4.1
<%@ page contentType="text/html; charset=GBK"%>
<%@ page language="java"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<style type="text/css">
table.default {
    width:510px;
}
table.default td {
    border:1px solid black;
    height:23px;
}
table.default td.item {
    background:#006589;
    color:#fff;
    text-align:center;
}
</style>

<script type="text/javascript">
var xmlHttp;    
function createXmlHttp() {
    if (window.XMLHttpRequest) {
       xmlHttp = new XMLHttpRequest();                  //FireFox、Opera等浏览器支持的创建方式
    } else {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//IE浏览器支持的创建方式
    }
}
function refreshCart() {
    createXmlHttp();                      
    xmlHttp.onreadystatechange = showCartIn;
    xmlHttp.open("GET", "cart.jsp" , true);
    xmlHttp.send(null);
}

function showCartIn() {
    if (xmlHttp.readyState == 4) {
/* thus, in this way, it return a jsp,so it is simple.if it return back a Servlet, it is difficult. this is a
very good idea. */
        document.getElementById("shoppingcart").innerHTML = xmlHttp.responseText;
    }
}
</script>
</head>

<body οnlοad="refreshCart()">
<div id="shoppingcart">
</div>
</body>
</html>

 


更多内容请见原文,文章转载自:https://blog.csdn.net/qq_43650923/article/details/103051814

posted @ 2021-12-17 18:53  malala  阅读(63)  评论(0编辑  收藏  举报