0
我無法顯示從asp.net WebMethod收到的結果。我有一個HTML模板,並填寫JSON響應的結果。問題是第一個響應正在顯示一次,第二個顯示2次,第三個4次,第四個8次等等。這裏是jQuery的(我需要引用「d」首先是因爲響應從asp.net和正在添加他們把它放在那裏自動)asp.net json顯示奇怪的結果
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....
不錯,你怎麼纔是唯一得到那個的?我也試過在聊天中詢問 - –
var newRow = $('。Template')。clone()。removeClass('Template') –