javascript - Query data from an API onto page in Node & Express without page refresh -


i have form on website user can fill out , return information page. page refreshes , wondering if possible without need complete page refresh, still have data auto update.

view

doctype html html     head     title= title     link(rel='stylesheet', href='/stylesheets/style.css')     body     form(name="yelp-form", method="post")         div.input             span.label city             input(type="text", name="city")             span.label  search term             input(type="text", name="term")         div.actions             input(type="submit", value="add")     block content 

route

router.post('/', function(req, res){     var businesses = [];     if(req.body.city === '' || req.body.term === ''){       res.render('api', {title: 'locatemycoffee', businesses: businesses});     }     // console.log(req.body);     // console.log(req);     yelp.search({location: req.body.city, term: req.body.term, category_filter: "food"}, function(error, data) {         var test = json.stringify(data); //changes yelps response json objects double quotes         test = json.parse(test); //json.parse can parse correctly after stringify used.         // for(var = 0; < ; i++){         // uncomment line below return every business matches query.         if(test['businesses'].length < 9){           cycles = test['businesses'].length;         }else{           cycles = 9;         }          for(var = 0; < cycles; i++){             var tempobject = {               name_information: test['businesses'][i]['name'],               imgur: test['businesses'][i]['rating_img_url'],               phone: test['businesses'][i]['display_phone']             };            businesses.push(tempobject);         };          console.log(test['businesses'][0]);          res.render('api', {title: 'locatemycoffee', businesses: businesses});      }); //end yelp search   });  module.exports = router; 


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -