-1

I would like to receive a data post or get sent in a javascript file. I don't want to send data I want to receive data. Thank you in advance.

Example: im enter url: http://example.com/javascript.js?parameter1=value1&parameter2=value2...

javascript.js:

var parameter1 = get_value("parameter1");
var parameter2 = get_value("parameter2");

function get_value(parameter_name){
//get value from url
}

  • It's not really clear what you're trying to accomplish. Is your JavaScript running in the browser? Server-side (node.js)? What data are you trying to read? For example, a GET request is generally just query string values in the URL. What stops you from reading those at this time? For a POST request that's data sent to a server, so to receive that data your code would be running on the server. The reading of which is part of pretty much any introductory tutorial on whatever server-side technology you're using. What are you trying and where are you stuck? – David Nov 23 '19 at 15:35
  • I want to know how to retrieve and process information in another JavaScript file in this file. Thanks – Erfan Jahanshahloo Nov 23 '19 at 15:57
  • I'm afraid that only made the question *less* clear. Perhaps you could provide a minimal example of what you're trying to do and indicate in that code what specifically isn't working or where specifically you're stuck? Questions like "how to send data" and "how to process information" are pretty vague and too broad. – David Nov 23 '19 at 15:59
  • im added example. thanks – Erfan Jahanshahloo Nov 23 '19 at 18:14
  • I've already voted to close this question for being unclear, but it's also now a duplicate of this one: https://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-get-parameters – David Nov 23 '19 at 18:16

2 Answers2

0

I am not sure I fully understand your question.

If you want to receive data from a server to your webpage you can do this with web sockets.

Please read about this:

font end: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API back end: https://www.npmjs.com/package/ws but you can use different librarys (this is only for nodeJS, other languages I do not know.)

I hope I could help.

Laurent Dhont
  • 1,012
  • 1
  • 9
  • 22
0

You need to create URLSearchParams and check the param available of not and then return the value of the query param

function get_value(key){
    var urlParams = new URLSearchParams(window.location.search);
    if(urlParams .has(key)){
     return urlParams .get(key)
    }else{
     return 'query param not available';
    }
}

for basic you can follow this link

Damodhar
  • 1,219
  • 8
  • 17