【发布时间】:2012-05-22 17:12:13
【问题描述】:
我希望能够获取 php 提供的 json 对象并将其放入 html 中。我的旧方法只是制作一个令人难以置信的长、难以理解的 html 字符串,然后执行 $.append(hmltStr) 在我最后一次在 SO 上发布它时并没有那么好。我想知道是否有人可以向我解释如何使用 this template 将 json 对象放入 html 中,这显然是对 John Resign micro-template 的改进。
给定对象:
{
"order": {
"name": "TRADEMARK WHEEL COMPANY",
"sales_order_id": "18278",
"order_date": "05 \u2044 15 \u2044 2012",
"due_date": "05 \u2044 21 \u2044 2012",
"order_number": "1213140",
"reference": "21192D\/35546",
"order_description": "BICICLETTE",
"ship_name": "ADAMS",
"ship_address1": "1919 W RANDOLPH ST.",
"ship_address2": "",
"ship_city": "CHICAGO",
"ship_state": "IL",
"ship_postal_code": "60606",
"ship_country": null,
"ship_via": "FEDEX GROUND",
"tracking_number": null,
"package_contents": null,
"freight": "0.00",
"taxable": "0.00",
"nontaxable": "748.88",
"sales_tax": "0.00"
},
"line_item": [{
"description": "RED ONE",
"quantity": "2.00",
"sell_price": "349.44"
},
{
"description": "FRONT GEAR",
"quantity": "2.00",
"sell_price": "15.00"
},
{
"description": "5th GEAR",
"quantity": "2.00",
"sell_price": "10.00"
}]
}
这个ajax请求正在收集data,如何在这个ajax函数的成功部分用它填充一个html表
$.ajax({
type: "POST",
url: "getJSON.php",
data: submitStr,
success: function (data) {
//populate order details
//loop through variable number of line items
}
<html>
<table id="contentTable">
</table>
</html>
另外,<script type="html/javascript></script> 标签是什么。这可能相关也可能不相关,但我在模板中看到了它;我需要使用它吗?
感谢您的帮助!
【问题讨论】:
标签: javascript jquery json jquery-templates