Can I send data using Javascript HTTP POST method?

I have the following Javascript form.

I want to send data / display using javascript throught HTTP POST method? Can I do that?

How can I do that? Once the user clicks on SUBMIT button the data should be displayed on the second page?

Here is my form:-
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
<!-- Start of FORM -->
<form method="POST" action="http://www.SFO.com">
Account Name: <input type="text" name="AC_Name" value="">
<br>
<br>
Account ID:   <input type="text" name="AC_Name" value="">
<br>
<br>
Opportunity ID: <input type="text" name="AC_Name" value="">
<br>
<br>

<input type="submit">


</form>
<!-- End of FORM -->

////////////////////////////////////////////////////////////////////////
SUMA ANANDSALESFORCE PROJECT MANAGERAsked:
Who is Participating?
 
b0lsc0ttConnect With a Mentor IT ManagerCommented:
You don't have to answer but why would you ever want Javascript to process the form?  The point of using forms is for the user to give you info.  If Javascript is used you don't really have the info, everything is still done by the browser on the clientside.  There are rare case where this may be OK but this question should help you understand why server scripts are an important part of this process.  That is how you get the info, either in your database, in an email, or by some other means but the server script does it while processing the form.

The question above and this comment is just rhetorical.  You mentioned you wanted to learn about this and this point is an important one that seems to be unclear.  There is no way to learn about or use POST if you leave the server out.

bol
0
 
b0lsc0ttIT ManagerCommented:
sumprit,

Do you mean you want Javascript to get and process the form?  It can't.  You should use server script to get the form and process it.

Let me know if I misunderstood the question.  If you have a question about server languages/scripts then let me know.  Let me know if you have any questions or need more information.

b0lsc0tt
0
 
SUMA ANANDSALESFORCE PROJECT MANAGERAuthor Commented:
Basically I need to understand how to send data using the HTTP POST method.
This is for my personal understanding. So I thought of this form designed in javascript and then I can use HTTP POST method, to send data across the server.

Since, I am doing this on my local machine, XP Professional installed, I would like the data to be displayed on the web page that I designed hosted on IIS - local host.

Can you help me understand how HTTP POST works using Javascript?

Is there a better option? I am comfortable with Javascript and ASP.Net?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
nizsmoDeveloperCommented:
Hi sumprit:

You can submit a form (POST) using javascript, but to get the POST or GET values you will need a serverside language such as ASP or PHP, etc...

Hope this helps :)
0
 
nizsmoDeveloperCommented:
Actually my above is not entirely true, you can (to a certain extent) get the GET values using javascript, but it is not very elegant, and i wouldn't recommend it..But don't think it is possible for POST values.
0
 
b0lsc0ttIT ManagerCommented:
The way you are doing it, with a form, is the most common way it is done and a good thing to learn.  Depending on your browser there are addons/extensions that will show you the headers.  That is what you would need to look at to see the "next part" of an HTTP POST.  This is the step where the headers, post, etc are sent to the server.

The best way to view this would be with server script.  Javascript isn't really useful in this case, the page is going away from the browser.  You don't have to use .NET but with IIS then ASP will be useful.  Use that for the server code.  You can look at the Request object or the Request.Form collection.

This is the way POST is used and handled.  If you have a more specific question about part of it then please elaborate.  I will be happy to provide more details or help as I can.  However there is a lot to POST so you won't learn it all here. :)

bol
0
 
SUMA ANANDSALESFORCE PROJECT MANAGERAuthor Commented:
what about using Querystrings in javascript?

Can I not use Querystrings to send data from one page to another?

How will that look like in the code pasted above?
0
 
b0lsc0ttIT ManagerCommented:
Querystrings would not use the POST method.  You would just need to change POST to GET though to have the querystring used.

There are some disadvantages and limits to using the query string though.  You could ask another question for details but 2 big ones are having the info in the URL and the limited length.

bol
0
 
SUMA ANANDSALESFORCE PROJECT MANAGERAuthor Commented:
Right.!

Here is First page
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <title></title>
</head>

<head>

</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<h1>Sending Data across the pages </h1>

<!-- Start of FORM -->
<form action="End.html" method="GET">
Account Name: <input type="text" name="first">
<br>
<br>
Account ID: <input type="text" name="second">
<br>
<br>
<input type="submit">
</form>
<!-- End of FORM -->


</body>
</html>

////////////////////////////////////////////////////////////////////////////////////////////////////////

Here is the second page which is retrieving the query strings:-

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
  <title></title>
 
<script LANGUAGE = "Javascript" type"test/javascript">
var qsParm = new Array();
function qs() {
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i=0; i<parms.length; i++) {
var pos = parms[i].indexOf('=');
if (pos > 0) {
var key = parms[i].substring(0,pos);
var val = parms[i].substring(pos+1);
qsParm[key] = val;
}
}
}
qsParm['first'] = null;
qsParm['second'] = null;
qs();

if (qsParm['first'] &&  qsParm['second'])
document.write('You entered' + qsParm['first']
continued from previous line + ' : ' + qsParm['second']);
</script>
 
</head>


<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">



<h1> This is the data </h1>
</body>
</html>

///////////////////////////////////////////////////////////////////////////////////


Notice how the query strings are used to display data from one page to another
0
 
b0lsc0ttIT ManagerCommented:
Right that is about all Javascript can do as far as "form processing."

Let me know what other questions you have on the original issue.  Being able to do that in Javascript when GET is used does not mean the same can be done with POST.  If that was the main question then, as I mentioned before, Javascript won't work.  The way POST forms are processed is with server script.  Let me know if you have a question about part of this still or need something clarified.

bol
0
 
b0lsc0ttIT ManagerCommented:
I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.