Home / Articles / Programming languages / Scripting languages / JavaScript / Analyzing GET request with JavaScript

Analyzing GET request with JavaScript

Analyzing GET request with JavaScript
 
Analyzing GET request with JavaScript
  • Currently 3 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Rating: 3/5 (1 votes cast)

Thank you for rating!

You have already rated this page, you can only rate it once!

Your rating has been changed, thanks for rating!

Log in or create a user account to rate this page.


GET requests (using address bar) can be easily analyzed with JavaScript. I’ll demonstrate this with the following example: write in the address bar any parameter in the format ?parameter=value&parameter=value...

Variables of the GET request: 

var tmp = new Array(); // two auxiliary
var tmp2 = new Array(); // arrays
var param = new Array();
 
var get = location.search; // string of the GET request
if( get != '' ) {
  tmp = ( get.substr( 1 ) ).split( '&' ); // split variables
  for( var i=0; i < tmp.length; i++ ) {
    tmp2 = tmp[ i ].split( '=' ); // array param will contain
    param[ tmp2[ 0 ] ] = tmp2[ 1 ]; // param key(name of the variable)->value
  }
  var obj = document.getElementById( 'greq' ); // screen output
  for( var key in param ) {
    obj.innerHTML += key + " = " + param[ key ] + "<br>";
  }
}

The key value is location.search (see article on base tag).


 

Read also

Post comment

basicuse.net
html5_css
106160485398655174790

Quick navigation

General navigation