1

I am coding a javascript http web server node, for a CDN project, I am used to PHP's

if ($_GET = "hello"); echo "Yey!"

but have no idea how to do so, I am new to javascript.

LJᛃ
  • 7,655
  • 2
  • 24
  • 35
alex tix
  • 175
  • 2
  • 7

2 Answers2

0

NodeJS

var url = require('url');
var url_parts = url.parse(request.url, true);
var query = url_parts.query;

Without NodeJS:
Use URI.js to get the query string. https://medialize.github.io/URI.js/

var uri = URI("urn:uuid:c5542ab6-3d96-403e-8e6b-b8bb52f48d9a?hello=world");
uri.protocol() == "urn";
uri.path() == "uuid:c5542ab6-3d96-403e-8e6b-b8bb52f48d9a";
uri.query() == "hello=world";
Venkat.R
  • 7,420
  • 5
  • 42
  • 63
0

You can Try this functions:

function httpGet(theUrl)
{
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
    xmlHttp.send( null );
    return xmlHttp.responseText;
}

However, synchronous requests are discouraged, so you might want to use this instead:

function httpGetAsync(theUrl, callback)
{
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.onreadystatechange = function() { 
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
            callback(xmlHttp.responseText);
    }
    xmlHttp.open("GET", theUrl, true); // true for asynchronous 
    xmlHttp.send(null);
}

Notes: Starting with Gecko 30.0 (Firefox 30.0 / Thunderbird 30.0 / SeaMonkey 2.27), synchronous requests on the main thread have been deprecated due to the negative effects to the user experience.

The Beast
  • 1
  • 1
  • 2
  • 24