Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to POST 2 values to a page using XMLHTTPRequest 1

Status
Not open for further replies.

dpimental

Programmer
Jul 23, 2002
535
US
Can anyone help me post two form values, including an xml tree to another page using the xmlhttpRequest object.

I have been researching this subject for some time; but can't find a clear answer on how to post values from a form to another page and get the responseText and parse it out?

Anyone? Please?


David Pimental
(US, Oh)
 
What does the page expect?
Code:
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") 
xmlhttp.open "POST", "[URL unfurl="true"]http://someurl",[/URL] false 
xmlhttp.setRequestHeader "Content-Type", "application/x-[URL unfurl="true"]www-form-urlencoded"[/URL] 
xmlhttp.send "xml=<myXML>blah</myXML>&value=blah"
Response.write xmlhttp.responseText 
set xmlhttp = nothing

Jon

"I don't regret this, but I both rue and lament it.
 
Thanks JontyMC. What I have is to form values, cmd and input. cmd is a flag to tell the processing page (this is an asp page) how to process the input (which will be xml).

So I need to send those to form values to the page, which will spit out an xml output, which I then must read and process, to see if the transaction was sucessfull.

Can the code above do this with form variables (values)?

David Pimental
(US, Oh)
 
Something along the lines of:
Code:
xmlhttp.send "cmd=" + CStr(Request("cmd")) + "input=" + CStr(Request("input"))
Whats the processing page? What values does it expect?

Jon

"I don't regret this, but I both rue and lament it.
 
Thanks again. Actually, I am doing some testing right now with an asp page. But the real page will be a servlet.

The servlet expects 2 "posted" values.

1. The "cmd" value posted, which tells it what type of process to expect, such as ...

cmd = "enroll" - This enrolls a person in the system
This must be associated with a "input" value, which is the xml structure and data for an enroll process, so ...
input = "Here I put the xml data for the enrollment"
Then both are posted to the servlet.

Does that explain what I am attempting to do?

David Pimental
(US, Oh)
 
My previous post is what you want then.

Jon

"I don't regret this, but I both rue and lament it.
 
Do I just use the xmlhttp.responseText to capture the response from the post?

David Pimental
(US, Oh)
 
Yep

Jon

"I don't regret this, but I both rue and lament it.
 
Cool, thanks for your help. XML is not my specialty, glad to know it's yours!

David Pimental
(US, Oh)
 
JontyMC, the code below ...
Code:
xmlhttp.send "cmd=" + CStr(Request("cmd")) + "input=" + CStr(Request("input"))

Can I say ...
Code:
[COLOR=grey yellow]xmlhttp.send "cmd=" + mycmd + "input=" + myinput[/color]

Where mycmd and myinput are asp variables holding the values that I want to post to the servlet?

David Pimental
(US, Oh)
 
I hate to sound dumb; but can you explain this code to me. Exactly what is it doing?

Code:
xmlhttp.send "cmd=" + CStr(Request("cmd")) + "input=" + CStr(Request("input"))

David Pimental
(US, Oh)
 
JontyMC, when there is an xmlhttp request and you use a "post", do you need to have form objects that contain those values (ie cmd and input) on the page you are doing the httprequest from.

Normally, if one page posts to another page, the first page would have the form objects and the second page would "request" the form objects from it?

Also, on the xmlhttp.send, do I need to specify a separator (i.e &) for multiple variables passing to the command.
like "command=" + cmd + "&input=" + input


David Pimental
(US, Oh)
 
1. No

Second page doesnt request the form objects. When the first page with the form is submitted, the browser grabs the form variables and posts them in an HTTP message to the server, which responds with the second page.

2. Yes

My post was wrong, should be:
Code:
xmlhttp.send "cmd=" + mycmd + "&input=" + myinput

Jon

"I don't regret this, but I both rue and lament it.
 
Thanks again. Yes I found some documentation on it that said the same thing.

David Pimental
(US, Oh)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top