title: Node Express pass variable from client to server
body: <p>I am trying to return value from an input box to a variable in route, by taking this <a href="http://mherman.org/blog/2013/10/20/handling-ajax-calls-with-node-dot-js-and-express-scraping-craigslist/#appjs-server-side" rel="nofollow">source</a> as a reference but am stuck, in the example author is searching a keyword, constructing a url using this keyword, and returning a body response. </p>
  
  <p>My use case is a little different I need user to provide a url as a string in search box, which I would then pass to my request function to spit response body</p>
  
  <p>Current app.js (server-side) </p>
  
  <pre><code>app.get('/searching', function(req, res){
  
    // input value from search
    var url = req.query.search;
    console.log(url); // prints value
  
    request({ uri: url}, function (error, response, body) {
      if (!error) {
        content = body;
        console.log(content);
      } else {
          console.log('Oops! Error when contacting slack.com');
      }
    });
  
  
    res.send(content);
  });
  </code></pre>
  
  <p>main.js (client-side)</p>
  
  <pre><code>    $(function(){
       $('#submit').on( 'click', function () {
          var sSearch = $('#search').val();
          var parameters = { search: sSearch };
             $.get( '/searching',parameters, function(data) {
             $('#results').html(data);
          });
      });
     });
  </code></pre>
  
  <p>I realize <code>/searching</code> in both above files must be replaced because currently its trying to 'search' the user entered url value as a query string, so if I enter "<a href="https://google.com" rel="nofollow">https://google.com</a>" in the text box the application tries to search:</p>
  
  <p><a href="http://localhost:3000/searching?search=https%3A%2F%2Fgoogle.com" rel="nofollow">http://localhost:3000/searching?search=https%3A%2F%2Fgoogle.com</a> </p>
  
  <p>instead I need it to pass this url as is to the <code>request</code> function so that I can print the <code>body response</code>, which in this case would be the page's source code. But am not sure how should I proceed</p>
  
  <p>index.jade (template)</p>
  
  <pre><code>extends layout
  
  block content
      input#search(type="search", placeholder="Enter Keyword")
      button#submit(type='submit',class='btn btn-success') Search
      h2#results
  
      script(src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js")
      script(src="/javascripts/main.js")
  </code></pre>
  
  <p>How should I format so that I can pass the variable from client to server and then send it back to client after processing? Any help is appreciated.</p>