<!-- getitem.hml 的script 代码如下-->
<html>
<head>
<meta charset="UTF-8">
<link href="static/assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="static/assets/global/css/components.css" rel="stylesheet" type="text/css"/>
<link href="static/assets/admin/pages/css/login.css" rel="stylesheet" type="text/css"/>
<script src="static/assets/global/plugins/jquery-1.11.0.min.js" type="text/javascript"></script>
<title>Title</title>
</head>
<body class="login">
<div class="content">
<h3 class="form-title">商品详情</h3>
<div class="form-group">
<label class="control-label">商品名</label>
<div>
<label class="control-label" id="title"/>
</div>
</div>
<div class="form-group">
<label class="control-label">商品描述</label>
<div>
<label class="control-label" id="description"/>
</div>
</div>
<div class="form-group">
<label class="control-label">价格</label>
<div>
<label class="control-label" id="price"/>
</div>
</div>
<div class="form-group">
<label class="control-label">图片</label>
<div>
<img id="imgUrl"/>
</div>
</div>
<div class="form-group">
<label class="control-label">库存</label>
<div>
<label class="control-label" id="stock"/>
</div>
</div>
<div class="form-group">
<label class="control-label">销量</label>
<div>
<label class="control-label" id="sales"/>
</div>
</div>
</div>
</body>
<script>
function getParam(paramName) {
paramValue = "", isFound = !1;
if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
while (i < arrSource.length && !isFound)
arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
}
return paramValue == "" && (paramValue = null), paramValue
}
var g_itemVO={};
jQuery(document).ready(function () {
console.info(getParam("id")+"---解析数据");
//获取商品详情
$.ajax({
type:"GET",
url:"http://localhost:8090/item/get",
data:{
"id":getParam("id")
},
//允许跨域请求
xhrFields:{withCredentials:true},
success:function (data) {
if (data.status=="success") {
g_itemVO=data.data;
reloadDom();
// alert("获取信息成功");
}else {
alert("获取信息,原因为" + data.data.errMsg);
}
},
error:function (data) {
alert("获取信息,原因为"+data.responseText);
}
});
});
function reloadDom(){
$("#title").text(g_itemVO.title);
$("#description").text(g_itemVO.description);
$("#price").text(g_itemVO.price);
$("#stock").text(g_itemVO.stock);
$("#sales").text(g_itemVO.sales);
$("#imgUrl").attr("src",g_itemVO.imgUrl);
}
</script>
</html>
获取URL的参数
wcqwcqwcqcqwdaawdqwd
Intest
从list页面跳转到详情页面,在详情页面获取id
在这里我把
$("#imgUrl").attr("src",g_itemVO.imgUrl);
写成了
$("#imgUrl").artt("src",g_itemVO.imgUrl);
导致图片和销量都刷不出来,还是要仔细啊