javascript - Call ajax from dynamic generated tag and fetch value from ajax -
i have fetched data ajax like
update
var = document.createelement('a'); a.setattribute('id', tr_job_room); a.setattribute('onclick', 'getgroupsdata(this.id)'); var audiolength; var ul_ul_li_a = document.createelement('a'); ul_ul_li_a.setattribute('class', 'dropdown-toggle'); ul_ul_li_a.setattribute('href', '#'); ul_ul_li_a.innerhtml = "audios"; ul_ul_li_a.setattribute('id', tr_job_room); if (audiolength > 0) { alert("audiolength"+audiolength); $(ul_ul_li_a).on('click', function () { alert(audiolength+"sdasds"); varid = this.id; audiosplay(varid); scriptpanel(); gettxtdata(); }); }
and ajax is:
// display groups data function getgroupsdata(arg) { $.ajax( { type: "post", url: '@url.action("getgroupsdata")', datatype: "json", mtype: "post", data: { arg: arg }, async: true, success: function (data) { audiolengh = data.groups[0].audio.length; audiodisplay(arg, data.groups[0].audio.length, data.groups[0].audio); } }); }
is correct way fetch data? not getting audiolength value in if
block suggestion?
you need put if
click event. execute function no matter what, put if statement function determine if of other functions should run:
$(ul_ul_li_a).on('click', function () { alert("audiolength"+audiolength); if (audiolength > 0) { alert(audiolength+"sdasds"); varid = this.id; audiosplay(varid); scriptpanel(); gettxtdata(); } });
i can't tell code, if dynamically generating sub-list under "air", may need change line on
to:
$(document).on('click', 'a.dropdown-toggle', function () {
update
i noticed in success
function, variable spelled audiolengh
instead of audiolength
.
Comments
Post a Comment