標籤:
ajax_典型應用_添加商品
1、設計思路
650) this.width=650;" title="clip_image002[4]" style="border-top:0px;border-right:0px;border-bottom:0px;border-left:0px;" border="0" alt="clip_image002[4]" src="http://s3.51cto.com/wyfs02/M02/59/C6/wKioL1ThrUOhHwVYAAAjg81mjxs918.jpg" height="44" />
2、關鍵代碼
<a href=”addToCart?id=oracle&price=200”>加入購物車ShoppingCart.javaMap<A,B> items = new HashMap<A,B>();items.containsKey(bookName)$.getJSON(url,args,function(data){})void doGet(…){doPost(….)
}
vid doPost(){
String bookName = request.getParameter(“id”);
int price =
HttpSession session = request.getSession();
ShoppingCart sc = (ShoppingCart) session.getAttribute(“sc”);
if(sc = null){
sc = new Shopping Cart();
session.setAttribute(“sc”,sc);
}
sc.addToCart(bookName.price);
StringBuilder result = new StringBuilder();
result.append(“{”)
.append(“’bookname’:’”+bookName+”’”)
650) this.width=650;" title="clip_image004" style="border-top:0px;border-right:0px;border-bottom:0px;border-left:0px;" border="0" alt="clip_image004" src="http://s3.51cto.com/wyfs02/M00/59/C6/wKioL1ThrUWDQU6EAAA80rg7RYw572.jpg" height="74" /> .
setContentttype(“text/javascript”);
setChar
}
preview 產看伺服器響應的資料結果
從服務端響應的json對象必須是雙引號
不需要時隱藏頁面顯示
var isHasCart = “${sessionScope.sc == null}”;
alert(isHasCart);
if(isHashCart == “true”){
$(“#cartstatus”).hide();
}else{
$(“#cartstatus”).show();
}
650) this.width=650;" title="clip_image006" style="border-top:0px;border-right:0px;border-bottom:0px;border-left:0px;" border="0" alt="clip_image006" src="http://s3.51cto.com/wyfs02/M01/59/C6/wKioL1ThrUfhLk19AAA4LH0fS_Y145.jpg" height="78" />
ajax_典型應用_添加商品標題