So i have this coffeescript function:
thestring = ""
$.get '/ajax/questions', (data) ->
counter = 0
dataLength = data.length
while counter < dataLength
thestring += "<option value=test>it wont work</option>"
counter++
console.log(thestring)
$("#question"+(numfilters+1)).append thestring
in my case, data is an array of arrays of length 2, (ex: [[hello,test],[hi,moretest]] ). The problem seems to be that my variable, "thestring", is only changed locally inside the function. When I attempt to log what the value is, i simply get whatever i initially assigned it (in this case the empty string). What I'm trying to do here is append options to a dynamically generated select box based on the data received from the ajax request.
$.getis an async function - you need a callback! You're trying to logthestringbefore the call has finished. Also, ditch thatwhileloop and useforloop.whileloops are used for reading data from a file - your data has a set end (the length) - so aforseems more appropriate