?
Solved

Read HTTP request using javaScript

Posted on 2003-02-18
9
Medium Priority
?
1,494 Views
Last Modified: 2008-02-01
How to read http request from the java script?

If User clicks on a link on a page, can I see the request browser sends to the server using java script? If so, how can I do this?

thanks
prasad
0
Comment
Question by:prasad_dixit
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 4

Expert Comment

by:whammy
ID: 7979047
You need a server-side language to do this.

Javascript is only executed client-side, as it interacts with the user's browser and doesn't have any way to interpret HTTP headers or requests sent to the server, since it is not hosted on the server.

If you need this kind of information, you need to use ASP, PHP, Perl, JSP, or another server-side language.
0
 
LVL 30

Expert Comment

by:third
ID: 7979295
if the method used is "get" (which is also the default), you can parse the values from the link of the next page.
0
 
LVL 4

Expert Comment

by:whammy
ID: 7979314
Actually that's all javascript CAN use is the "get" method...

function QueryString(str) {
   var q = window.location.search;
   var foundValue = ""
   if (q.length > 1) {
      this.q = q.substring(1, q.length);
   }
   this.keyValuePairs = new Array();
   if (q) {
      for (var i = 0; i < this.q.split("&").length; i++) {
         this.keyValuePairs[i] = this.q.split("&")[i];
         if (this.keyValuePairs[i].split("=")[0] == str) {
            foundValue = unescape(this.keyValuePairs[i].split("=")[1]);
         }
      }
   }
   return foundValue;
}

If you use:

document.write(QueryString('blah'))

and "blah" is in the querystring, then javascript should return the value...

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:third
ID: 7979366
hmmm, whammy you changed your mind huh! ;-)
0
 
LVL 2

Expert Comment

by:uvals
ID: 7979778
Whenever user clicks on a link the following script shows the URI requested....

==========================================================
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Read HTTP Request</title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="Reddicharla">
<script>
function getURI() {
    var el = window.event.srcElement;
    while ((el != null) && (el.tagName != "A")) {
        el = el.parentElement;
     }
    if (el != null) {
          //Requested URI
          var uri = el.href;
          alert("Requested URI: \n\n" + uri);
     }
    //window.event.cancelBubble = true;
}
</script>
</head>

<body onclick="getURI();">
<h1>welcome!</h1>
<a href="hello.html">This is a very <B>short</B> document.</a>

</body>
</html>
==========================================================

-Uvals
0
 
LVL 2

Expert Comment

by:uvals
ID: 7979800
If you want to cancel the navigation then include this line...

window.event.returnValue = false;

-Uvals

 
0
 

Author Comment

by:prasad_dixit
ID: 7988247
Thanks all,

My requirement is kind of more than what you guys have commented. The thing is that, i need to know all the http request parameters including HTTP header and body. May be I need to fetch the link invisibly, when user moves his mouse over the link. And then read all the http headers and body.
IS there any way I can do this invisibly and get http info. My Ultimate goal is to show the user HTTP information when he moves his mouse over the link.

I hope i havent confused u guys ;)

Please comment

thanks
prasad
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10414015
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 10446402
PAQed, with points refunded (50)

Computer101
E-E Admin
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question