javascript - asp.net json displaying weird results -
i having trouble displaying results recieved asp.net webmethod. have html template , fill in results json response. problem first response being displayed once, second displayed 2 times, third 4 times, fourth 8 times , on . here jquery (i need reference "d" first because response comming asp.net , put there automatically)
function fngetcontent(keyword) { var newkeyword = keyword.tag; var type = keyword.type var oldresults = $("#fillresultsdiv").html() $('#hidquerytype').val('tagsearch'); $.ajax({ type: "post", //getevents(itype integer, ssearch 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(); // loop through object (var prop in this) { if (this.hasownproperty(prop)) { // lucky you, keys match classes :) $('.' + prop, newrow).text(this[prop]); } } $('#fillresultsdiv').append(newrow); });
there 1 entry in json each event, jquery code making happen, sample response:
{"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....
each time call
var newrow = $('.template').clone();
you creating copy of elements have "template" class. appending these copies element id "fillresultsdiv". each 1 of these copies has "template" class applied it, next time clone, picking cloned copies.
the first time call there 1 row, second time 2, 4, 8, etc.
you can change cloning line to
var newrow = $('.template').clone().removeclass("template");
Comments
Post a Comment