2013年9月6日 星期五

使用POST取得JSON資料

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title></title>
<!--JQUERY UI-->
<script type="text/javascript" src="http://web.systemlead.com/bufferorderweb/scripts/jquery-2.0.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">
$(function () {
ShowMenu();
});
//顯示菜單
function ShowMenu() {
var TRANSDT = '2013-09-07';
var BOSTORE_NO = '30001000'
jQuery.ajax({
url: 'http://web.systemlead.com/bufferorderweb/OrderProcess.aspx/ShowMenu',
type: 'post',
contentType: "application/json; charset=utf-8",
data: '{"BOSTORE_NO":"' + BOSTORE_NO + '","TRANSDT":"' + TRANSDT + '"}',
dataType: 'json',
success: BindMenuItem,
error: function () {
alert("error");
}
});
}
function BindMenuItem(response) {
//alert(response.d);
var rList = $.parseJSON(response.d);
var tmp = "";
$.each(rList, function (i, item) {
//alert(item.aVAILABLE_QTYField);
var str1 = "";
if ((item.aVAILABLE_QTYField).toString() != "0") {
str1 = "<input type='button' class='add' />"
+ "<input type='text' placeholder='0' class='align-center' value='0' onkeypress='TextBoxNumCheck_Int();' "
+ "id='txt" + item.mEALNOField + "' alt='" + item.mEAL_PRICEField + "'>"
+ "<input type='button' class='less' />"
+ "<span class='checkNumber'>數量:0</span>";
}
else {
str1 = "<button class='info disabled center'>已售完</button>";
}
tmp = tmp + "<div alt='dishesList _" + item.cAEGORY_NOField + "' id='" + "divMEALKIND" + item.mEALKINDField + "'>"
+ "<h2>" + item.mEALNAField + "</h2>"
+ "<span class='roll' title='" + item.dESCTXTField + "'></span>"
+ "<img src='http://web.systemlead.com/bufferorderweb/show_image.ashx?W=190&H=220&FID=" + item.fIDField + "' "
+ "alt='" + item.mEALNOField + "' title='" + item.dESCTXTField + "' "
+ "id='img" + item.mEALNOField + "' />"
+ "$" + item.mEAL_PRICEField + "元 <span>每日供應" + item.dATE_LIMITField + "份</span>"
+ "<div class='dishesMenu'>"
+ str1
+ "</div></div>";
});
$("#rptMain").children().remove();
$("#rptMain").append(tmp);
}
</script>
</head>
<body>
<form>
<div id='rptMain'></div>
</form>
</body>
</html>
view raw getJson.html hosted with ❤ by GitHub
WebMethod
/// <summary>
/// 繫結菜單
/// </summary>
[System.Web.Services.WebMethod]
public static string ShowMenu(string BOSTORE_NO, string TRANSDT)
{
DateTime dt = Convert.ToDateTime(TRANSDT);
List<BOSMEAL> result = BOSMEAL_SelectDailyMenu(BOSTORE_NO, dt).ToList<BOSMEAL>();
return JsonUtility.ToString<List<BOSMEAL>>(result);
}
view raw ShowMenu.cs hosted with ❤ by GitHub

沒有留言:

張貼留言