Thursday 15 March 2012

javascript - jquery undefined data return in ajax -



javascript - jquery undefined data return in ajax -

i'm using jquery mobile, , need remove undefined word comes above label. data json homecoming sucessfuly , build html correctly. except undefined have dynamic code

html

<div class="ui-field-contain" id="selectnovocoranimal"> </div>

javascript

function coranimal(data){ var html html += '<label for="cornovoanimal" class="select">cor</label>' html += '<select name="cornovoanimal" id="cornovoanimal" data-native-menu="false">' $.each(data, function (i, x) { html+='<option value='+ x.id + '>'+ x.descricao +'</option>'; }); html += '</select>' $('#selectnovocoranimal').html(html).enhancewithin(); }

which build this:

undefined <<< need remove cor [amarelo] << select

why giving me undefined?

this because not giving html variable initial value, value undefiend. when go seek concat rest of html strings it converts undefiend string version , rest of html added that.

simply set initial value

var html = "";

javascript grails

No comments:

Post a Comment