ajax_典型應用_添加商品標題

來源:互聯網
上載者:User

標籤:

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_典型應用_添加商品標題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.