javascript - Passing Server Side Javacript Array to Client -
i have select menu displaying list of options
i need use server side javascript call external 3rd party db, , return , array. , have client side javascript calling array , populating options in select menu.
i not how can pass array server side client side. client side javscript , server side javascript, not how pass array server client side. input appreciated. code below.
server side javascript
var arrayoptions = new array(); arrayoptions= //call db here for(var = 0; < arrayoptions.length; i++) { var opt = arrayoptions[i]; arrayoptions.push(opt); }
client side javascript
function getoptions(arrayoptions){ var select = document.getelementbyid("seloption"); for(var = 0; < arrayoptions.length; i++) { var opt = arrayoptions[i]; var el = document.createelement("option"); el.textcontent = opt; el.value = opt; select.appendchild(el); }
well, passing data server client involves ajax requests. instance, post request, can sent server , server can respond you'd like. i'm not sure how you're running server, slight feeling might not running server exactly. advice learn how client/server communication works first, sending array easy sending string or number. suggested reading:
node.js - serverside javascript ajax - sending data server without reloading page
Comments
Post a Comment