使用AJAX在显示标签加载JSON数据 [英] Load json data in display tag by using ajax
问题描述
JQuery的
jQuery.noConflict();
jQuery(document).ready(function(){
jQuery("#stallId").change(function(e){
//prevent default action
e.preventDefault();
jQuery.ajax({
url: "getProducts.html?method=Product&stallId="+document.getElementById("stallId").value,
dataType: "json",
success: function(json){
if(json.status == true){
var strHtml='';
strHtml=+"";
for(var i=0;i<json.promotionProductList.length;i++){
}
}
},
failure: function(){
alert( "FAILED" );
}
});
});
});
显示标记
<display:table name="ProductList" id="product" class="table" export="false">
<display:column escapeXml="true" titleKey="productForm.name">
</display:column>
</display:table>
在动作类
Map productMap = new HashMap();
productMap.put("id", "1");
productMap.put("name", "Coca Cola");
List<Product> productList = new ArrayList<Product>();
productList.add(productMap);
jsonWriter.object()
.key("status").value(true)
.key("pList").value(productList)
.endObject();
如何用ajax加载在显示标签JSON数据?当我选择从DropDownList的一个摊位,将其发送该URL到后端动作类和能够得到的地图产品的名单,但我不知道如何使数据在显示标签显示。可能有人帮助我,并告诉我如何加载数据?顺便说一句,我用struts 1。
How to load json data in display tag using ajax? When I select a stall from dropdownlist, it send the url to back end action class and able to get list of map of Products, but I not sure how to make the data to display in display tag. Could someone help me out and tell me how to load the data? Btw I'm using struts 1.
推荐答案
在我检查使用萤火显示标签的一部分,我已经发现,在显示标签会更改为普通的HTML表格。因此,在阿贾克斯:
After I check the display tag part using firebug, I have found out that the display tag will be change to normal html table. So in ajax:
success: function(json){
if(json.status == true){
var strHtml='';
for(var i=0;i<json.pList.length;i++){
strHtml+='<tr><td>'"+json.pList[i].name+"'</td></tr>';
}
jQuery("table#product tbody").html(strHtml);
}
},
在jQuery的(表#产品TBODY), 表是指显示table标签, 和#product是指显示表ID。
In jQuery("table#product tbody"), the "table" refers to display table tag, and the #product refers to display table id.
这篇关于使用AJAX在显示标签加载JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!