0

I've been looking for information on how I can send a client side variable to the server side using JavaScript. I'm a beginner and working on my first full stack web app and essentially i want to do something like this;

var userInput = $('#location-city').val();

This is taking in the value of a <input id="location-city"> in my html file on the client side.

I want to send this variable userInput to the server side where I use it with an API in the following manner:

baseUrl + userInput

This would add the userInput (which would be a city) to the baseUrl of my API and then return locations in a certain city. The reason why my API needs to stay on server side is because I'm using secret id's and tokens.

rhens
  • 4,791
  • 3
  • 22
  • 38
  • 4
    Did you use the search and had a look at any of the questions/answers in [`[javascript] pass variable to server`](https://stackoverflow.com/search?q=[javascript]+pass+variable+to+server)? If not, please do that before asking a new question. – Felix Kling Nov 29 '15 at 23:34
  • Perhaps this post too http://stackoverflow.com/questions/19014257/sending-data-from-a-browser-to-a-server-and-back – Rashwan L Nov 29 '15 at 23:38
  • Could you give me more detail,sir? I thought you just need to get GET PARAMETER in your server side and use GET URL in your client side, but give me more info anyway. – Sarin Suriyakoon Nov 29 '15 at 23:56
  • You should look at the jquery api for http and Ajax they have functions that can handle this – Binvention Nov 29 '15 at 23:58
  • Take a look at this question [transfer-data-from-one-html-file-to-another](http://stackoverflow.com/questions/17502071/transfer-data-from-one-html-file-to-another) it can solve your problem – Ahmed Khan Nov 30 '15 at 10:18
  • Possible duplicate of [How to I send data from JavaScript to PHP and vice versa?](http://stackoverflow.com/questions/1968296/how-to-i-send-data-from-javascript-to-php-and-vice-versa) –  Nov 30 '15 at 18:02
  • so ive looked through those resources and alot of them are using c++ or ASP.NET which I'm not using either. The examples are also transferring global variables to different html files...I'm trying to send mine from a main.js file to a server.js file... – Eddy Chang Nov 30 '15 at 20:00

0 Answers0