我无法显示从 asp.net WebMethod 收到的结果。我有一个 HTML 模板并填写 JSON 响应的结果。问题是第一个响应显示一次,第二个显示2次,第三个显示4次,第四个显示8次,依此类推。这是jQuery(我需要先引用“d”,因为响应来自asp.net,它们会自动将其放在那里)
function fnGetContent(keyword) {
var NewKeyword = keyword.tag;
var type = keyword.type
var oldresults = $("#fillresultsdiv").html()
$('#hidQueryType').val('tagsearch');
$.ajax({
type: "POST", //GetEvents(iType As Integer, sSearch As String)
url: "Default.aspx/GetEvents",
data: "{'iType':'" + type + "','sSearch' : '" + NewKeyword + "' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var events = [];
var obj = $.parseJSON(msg.d);
$.each(obj.res, function() {
var newRow = $('.Template').clone();
// Now loop through the object
for (var prop in this) {
if (this.hasOwnProperty(prop)) {
// Lucky for you, the keys match the classes :)
$('.' + prop, newRow).text(this[prop]);
}
}
$('#fillresultsdiv').append(newRow);
});
每个事件的 JSON 中只有一个条目,是 jQuery 代码实现了这一点,示例响应:
{"d":"{\"res\":[{\"day\":\"26\",\"dayofweek\":\"Tue\",\"month\":\"Jun\",\"title\":\"Glen Hansard\"
,\"venue\":\"Vic Theatre\",\"time\":\"7:00 PM\",\"ticketurl\":
\"http://seatgeek.com/glen-hansard-tickets/chicago-illinois....