ajax_典型应用_添加商品标题

ajax_典型应用_添加商品

1、设计思路

clip_image002[4]

2、关键代码

<a href=”addToCart?id=oracle&price=200”>加入购物车
ShoppingCart.java
Map<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+”’”)

clip_image004 .

setContentttype(“text/javascript”);

setChar

}

preview 产看服务器响应的数据结果

从服务端响应的json对象必须是双引号

不需要时隐藏页面显示

 
         
         
         
         

var isHasCart = “${sessionScope.sc == null}”;

alert(isHasCart);

if(isHashCart == “true”){

$(“#cartstatus”).hide();

}else{

$(“#cartstatus”).show();

}

clip_image006

你可能感兴趣的:(Ajax,添加标题)