title: how to populate html drop down with nodejs data
body: <p>I want to populate a select drop down menu in HTML/PHP with JSON data from NodeJS. How can I do this? I'm getting all the JSON flight data when I run localhost:3000/arrivals/flights so I know the code is correct but how do I transfer the data from index.js to the liveArrivalsNode.php dropdown menu?</p>
  
  <p>liveArrivalsNode.php</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;link rel="stylesheet" href="colour.css"&gt;
      &lt;script src="liveArrivalsNode.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;?php
  require 'airportArrivals.html';
  ?&gt;
  
      &lt;form method="GET" action="arrivals/flights"&gt;
          Filter by Flight No.:
          &lt;select class="flight" id="flights" name="flight"&gt;
              &lt;option value="All"&gt;Any&lt;/option&gt;
  
      &lt;/select&gt;
      &lt;/form&gt;
  &lt;p&gt;
  &lt;div id="myFlights"&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;footer&gt;
  &lt;caption align="bottom"&gt;&lt;hr/&gt;&lt;center&gt;L00091898
  &lt;/footer&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>liveArrivalsNode.js</p>
  
  <pre><code>var xmlhttp;
  
  window.onload=function(){           
      getAjaxData();
      setInterval(getAjaxData, 5000);
  
      // document.getElementById("flights").onchange=function(){
      // getAjaxData();
  }
  
  function getAjaxData() {
      if (window.XMLHttpRequest)
          xmlhttp=new XMLHttpRequest();
      else
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  
      xmlhttp.onreadystatechange=function (){
          showAjaxData();
      };
  
       xmlhttp.open("GET","http://localhost:3000/arrivals/",true);
       xmlhttp.send();
  }
  
  function showAjaxData()
  {
      if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
      {       
          var data = JSON.parse(xmlhttp.responseText);
  
          var output="&lt;table border=1&gt;";
          output+="&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;Origin&lt;/th&gt;&lt;th&gt;Airline&lt;/th&gt;&lt;th&gt;Flight&lt;/th&gt;&lt;th&gt;Scheduled Date&lt;/th&gt;&lt;th&gt;Scheduled Time&lt;/th&gt;&lt;th&gt;Status&lt;/th&gt;";
          for(var i=0;i&lt;data.arrivals.length;i++)  // for each fixture 
          {
              var terminal;
              if(data.arrivals[i].terminal == "t1")
                  terminal = "&lt;img src='images/t1.jpg'/&gt;";
              else
                  terminal = "&lt;img src='images/t2.jpg'/&gt;";
  
              output += '&lt;tr&gt;&lt;td&gt;'+terminal+'&lt;/td&gt;&lt;td&gt;'+data.arrivals[i].origin+'&lt;/td&gt;&lt;td&gt;'+data.arrivals[i].airline+'&lt;/td&gt;&lt;td&gt;'+data.arrivals[i].flight+'&lt;/td&gt;&lt;td&gt;'+data.arrivals[i].scheduledDate+'&lt;/td&gt;&lt;td&gt;'+data.arrivals[i].scheduledTime+'&lt;/td&gt;&lt;td&gt;'+data.arrivals[i].status+ '&lt;input type=\'hidden\' name=\'highlight\' value=\'data.arrivals[i].highlight\'&gt;&lt;/td&gt;&lt;/tr&gt;';
          }
          output+="&lt;/table&gt;";
  
          // add output to "fixtures" div
          document.getElementById("myFlights").innerHTML=output;
      }
  }
  </code></pre>
  
  <p>index.js</p>
  
  <pre><code>var express = require("express");
  var mysql = require('mysql');
  var app = express();
  var moment = require('moment');
  var data;
  var output;
  
  var cors = require('cors');   // NB! Needed below.
  var flightNo;
  var connection = mysql.createConnection({
      host     : 'localhost',
      user     : 'root',
      password : '',
      database : 'airportdb'
  });
  
  // add route below
  app.get("/arrivals/", cors(), function(req,res){
  
  connection.query("SELECT * FROM arrivals", function(err, rows, fields) {
      if (err) throw err;             
  
      data = JSON.stringify(rows);
  
      res.writeHead(200, {"Content-Type": "text/json"});
      res.write("{ \"arrivals\":" + data+"}");
      res.end();      
      });
  });
  
  app.get("/arrivals/flights", cors(), function(req,res){
      // flightNo = req.params.flightNo;
  
      connection.query("SELECT flight FROM arrivals", function(err, rows, fields) {
          if (err) throw err;             
  
          output = JSON.stringify(rows);
  
          res.writeHead(200, {"Content-Type": "text/json"});
          res.write("{ \"flights\":" + output+"}");
          res.end();      
          });
  });
  
  
  var myServer = app.listen(3000, function() {
      soconsole.log("Server listening on port 3000");
  });
  </code></pre>