我正在通過 URL 從外部站點(Cross Origin..)獲取一些資料,我想將結果(每個)顯示到他們自己的 html div 中。
我該怎么做,最簡單有效的方法是什么?
這是當前代碼
<script>
$.ajax({
dataType: "json",
url: 'https://*****************/DirectDownload/GetShopProducts?token=*********&searchString=polo',
success: function(products){
var html = '<div>';
$.each(products, function (index, value) {
html = '<h2>Item Code:</h2><p>' value.ItemCode '</p>';
});
html = '</div>';
$('#output').html(html);
}
});
</script>
控制臺日志中的結果
[
{
"ItemCode":"1100-M-NV-FER03EM2-FER",
"Description":"Osprey Deluxe Poloshirt",
"TechnicalInfo":"",
"ImageName":"1100NAR.jpg",
"FfProductCode":"1100-M-NV-EM2-FER",
"CategoryDescription":"PoloShirts",
"CategoryImage":"******.**.**/web/images/category_poloshirt.jpg"
},
{
"ItemCode":"1160-20-NV-FER03EM1-FER",
"Description":"Wren Ladies Poloshirt",
"TechnicalInfo":"",
"ImageName":"1160NAR.jpeg",
"FfProductCode":"1160-20-NV-EM1-FER",
"CategoryDescription":"Polo Shirts",
"CategoryImage":"https://******.**.**/web/images/category_poloshirt.jpg"
}
]
我想實作如下
<script>
$.ajax({
dataType: "json",
url: 'https://*****************/DirectDownload/GetShopProducts?token=*********&searchString=polo',
success: function(products){
for each {
<div>
<h2>Item Code:</h2><p>$ItemCode</p>
<h2>Item Code:</h2><p>$description</p>
....
</div>
}
});
</script>
uj5u.com熱心網友回復:
像這樣的東西?:
success: function(data){
var html = '<div>';
$.each(data, function (index, value) {
html = '<h2>Item Code:</h2><p>' value.ItemCode '</p>';
});
html = '</div>';
$('#result').html(html); //here you set the html variable with the collected data into your desire html tag.
},
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/513508.html
