function invokeJava(action, data, isShowLoading) { if(typeof(isShowLoading) == "undefined" || isShowLoading) { showLoading(); } var result = $.ajax({ url: action, method: "POST", data: data, async: false, success : function(msg) { } }); if(isShowLoading == undefined || isShowLoading) { hideLoading(); } return result.responseText; } function showLoading() { $("body").append("<div class='hs_mask'><img src='img/loading.gif'></div>"); } function hideLoading() { setTimeout(function(){ $("div.hs_mask").remove(); }, 100); }
此为异步加载数据
调用方法
function getParam(suitId,quantity){ var data ={}; data["suitId"] = suitId; data["quantity"] = quantity; return data; }
function addCartForSuit(){ var suitId = $("#suitId").attr("value"); var quantity = $("#quantity").attr("value"); var param = getParam(suitId,quantity); var result = invokeJava("addCartForSuitAjax",param);//addCartForSuitAjax 为一个action if(result == "成功"){ if(confirm("加入购物车成功,是否进入购物车")){ window.location.href= "getCartForUcboss3_ShoppingCart"; }else{ history.go(-1); } }else{ alert(result); } }