1.當你從背景傳一個值到前台時 用this.getResponse.getWriter().println(參數);
2.前台接受這個參數的js為var result = xmlhttp.responseText;
if(parseInt(result)==1){
show_notice('你想輸出提示語句');
}else if(parseInt(result)==0){
show_notice('你想輸出提示語句');//其中1和0是指你的判斷條件如你指定成的話 this.getResponse.getWriter().println(參數);參數為1
}
3.在實作購物車的添加一個或減少一個商品,商品數量和總價的實時重新整理的ajax
關鍵代碼var Id="menu"+id;
var num=parseInt(document.getElementById(Id).innerHTML);//表示獲得頁面上的id和對應的數量
document.getElementById(Id).innerHTML=num+1;
document.getElementById("total").innerHTML=result;//表示把背景的改變傳入到前台顯示在頁面上