jquery jason代码片段
<script type="text/javascript">
$(function () {
$("#btnOK").click(function () {
$.ajax({
type: "post", //访问WebService使用Post方式请求
//contentType: "application/json",
dataType: "json",
url: "/Application/WenDaHandler.ashx",
data: {type:"g"},
error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); },
success: function (data, textStatus) {
if (data != null) {
var con = "";
var tb = "<Table>";
for (var i = 0; i < data.length; i++) {
tb += "<tr><td>" + data[i].UserName + "提问:" + data[i].PostTitle + "十分钟前" + data[i].LastReplyLink+ "</td></tr>";
}
// alert(tb);
tb = tb + "</table>";
$("#divContent").html(tb);
}
else {
alert(textStatus);
alert("msgisnull");
}
}
});
});
$("#btnOK").click(function () {
$.getJSON("/Application/WenDaHandler.ashx", { type: "g" }, function (arrs) {
var tb = "<Table>"; alert(tb);
$.each(arrs, function (i, item) {
tb += "<tr><td>" + item.UserName + "提问:" + item.PostTitle + "十分钟前" + item.LastReplyLink + "</td></tr>";
});
tb += "</Table>";
$("#divContent").html(tb);
});
});
});
</script>