Is there a way to get values from database (or XML file) using ASP.NET and then inject them into a JavaScript array?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Either of the approaches (AJAX or Literals) will work, for ‘getting data’.
I tend to use literals when the page is generated for passing through ‘configuration’ and use AJAX requests (returning JSON) for retrieving data. Although with small amounts of data you might be better served just using literals embeded in your page. If you’re doing this from an included JS file though you’ll more likey want to use AJAX calls.
An example of a object literal might be …
Remember that you can serialize to XML and use a parser in your Javascript too, although this is less common and usually has a performance overhead.