Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #15534 > unrolled thread
| Started by | Gene Wirchenko <genew@ocis.net> |
|---|---|
| First post | 2012-08-23 15:00 -0700 |
| Last post | 2012-08-26 14:59 +0100 |
| Articles | 2 on this page of 22 — 11 participants |
Back to article view | Back to comp.lang.javascript
XMLHttpRequest: POST with Data Gene Wirchenko <genew@ocis.net> - 2012-08-23 15:00 -0700
Re: XMLHttpRequest: POST with Data "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-08-23 22:48 +0000
Re: XMLHttpRequest: POST with Data Gene Wirchenko <genew@ocis.net> - 2012-08-23 16:40 -0700
Re: XMLHttpRequest: POST with Data "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-08-26 20:39 +0000
Re: XMLHttpRequest: POST with Data Christoph Becker <cmbecker69@gmx.de> - 2012-08-24 01:11 +0200
Re: XMLHttpRequest: POST with Data Gene Wirchenko <genew@ocis.net> - 2012-08-23 16:42 -0700
Re: XMLHttpRequest: POST with Data Christoph Becker <cmbecker69@gmx.de> - 2012-08-24 02:54 +0200
Re: XMLHttpRequest: POST with Data Gene Wirchenko <genew@ocis.net> - 2012-08-23 19:04 -0700
Re: XMLHttpRequest: POST with Data Tim Streater <timstreater@greenbee.net> - 2012-08-24 08:57 +0100
Re: XMLHttpRequest: POST with Data Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-25 12:02 +0200
Re: XMLHttpRequest: POST with Data Christoph Becker <cmbecker69@gmx.de> - 2012-08-25 14:09 +0200
Re: XMLHttpRequest: POST with Data Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-25 15:20 +0200
Re: XMLHttpRequest: POST with Data Christoph Becker <cmbecker69@gmx.de> - 2012-08-26 15:49 +0200
Re: XMLHttpRequest: POST with Data Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-26 19:15 +0200
Re: XMLHttpRequest: POST with Data Stefan Weiss <krewecherl@gmail.com> - 2012-08-26 19:54 +0200
Re: XMLHttpRequest: POST with Data Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-26 21:43 +0200
Re: XMLHttpRequest: POST with Data Christoph Becker <cmbecker69@gmx.de> - 2012-08-26 23:42 +0200
Re: XMLHttpRequest: POST with Data Denis McMahon <denismfmcmahon@gmail.com> - 2012-08-24 02:55 +0000
Re: XMLHttpRequest: POST with Data "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-08-23 19:28 -0700
Re: XMLHttpRequest: POST with Data "Tom de Neef" <tdeneef@qolor.nl> - 2012-08-24 15:58 +0200
Re: XMLHttpRequest: POST with Data Ross McKay <au.org.zeta.at.rosko@invalid.invalid> - 2012-08-26 08:38 +1000
Re: XMLHttpRequest: POST with Data Mike Winter <usenet@michael-winter.me.invalid> - 2012-08-26 14:59 +0100
Page 2 of 2 — ← Prev page 1 [2]
| From | Ross McKay <au.org.zeta.at.rosko@invalid.invalid> |
|---|---|
| Date | 2012-08-26 08:38 +1000 |
| Message-ID | <a5ki381sac4ilu5l208ql90h2dj988r55t@4ax.com> |
| In reply to | #15534 |
On Thu, 23 Aug 2012 15:00:37 -0700, Gene Wirchenko wrote:
> 1) I can not get POST to work according to various documentation I
>have found on the Web.
>
> Suppposedly, the .open() and .send() would be
> oRequest.open("POST",Url,true);
> oRequest.send(DataToSend);
>but with this, at the server end, the .QueryString value is ""
>regardless of what was supposedly sent.
>[...]
By design; .QueryString contains the contents of the GET query string,
not the form POST. You want to look in .Form instead. If you want to
handle GET and POST interchangeably, you should instead drop both
.QueryString and .Form and just access your values from the Request
object, which will aggregate the two into one collection. e.g.
{url}?a=1&b=2
Request.QueryString("a") => 1
Request.Form("a)" => ' not found
Request("a)" => 1
{url} with form post a=1, b=2
Request.QueryString("a") => ' not found
Request.Form("a)" => 1
Request("a)" => 1
> 2) What should I do for escaping of data? Going to the server, any
>line breaks get eaten somewhere so I use escape() at browser and
>unescape() at server. Going from server to browser, line break are
>not eaten. Does this mean that I do not have to escape()/unescape()
>on the trip back?
>
> Are escape() and unescape() the correct functions to use?
To send data in a form post or querystring, you need to encode the data
with encodeURIComponent() on the browser when you are building the post
data or query string. See this example in GIST:
https://gist.github.com/3110728
When sending data back from the server, it totally depends on what
format your data is as to how to escape it. If you are using JSON, you
will need to escape it per JavaScript strings, e.g. replace CR with "\r"
and LF with "\n", etc. Use a library of code that handles that (none
build into Classic ASP); here's one attempt at such:
https://github.com/webaware/ASP-JSONEncode
If you are sending back XML, you should build your XML using Microsoft's
XML DOM object (in MSXML):
http://msdn.microsoft.com/en-us/library/windows/desktop/ms766487(v=vs.85).aspx
If you are sending back HTML to replace some page content, you should
use Server.HTMLEncode():
http://msdn.microsoft.com/en-us/library/ms525347(VS.90).aspx
--
Ross McKay, Toronto, NSW Australia
"Let the laddie play wi the knife - he'll learn"
- The Wee Book of Calvin
[toc] | [prev] | [next] | [standalone]
| From | Mike Winter <usenet@michael-winter.me.invalid> |
|---|---|
| Date | 2012-08-26 14:59 +0100 |
| Message-ID | <aZp_r.149382$UL.133535@fx19.am4> |
| In reply to | #15534 |
On 23/08/2012 23:00, Gene Wirchenko wrote:
> Dear JavaScripters:
>
> I am trying to pass data back and forth using XMLHttpRequest. I
> have run into a few issues. The first one is the most important.
>
> 1) I can not get POST to work according to various documentation I
> have found on the Web.
>
> Suppposedly, the .open() and .send() would be
> oRequest.open("POST",Url,true);
> oRequest.send(DataToSend);
> but with this, at the server end, the .QueryString value is ""
> regardless of what was supposedly sent.
>
> I have found that using the GET style of
> oRequest.open("POST",Url+"?"+DataToSend,true);
> oRequest.send();
> does work. At least, it appears to.
>
> Am I doing something wrong, or is the documentation wrong?
As has been indicated, you're looking in the wrong place for the data.
The query string (.QueryString) is part of the URL used to locate the
receiving page, hence when you modify the URL in the second example, the
information is available.
The POST method adds data as a "payload" in the request body sent to the
server, and this is accessed differently through the Request.Form
collection[1].
If you're new to authoring server-side and you haven't already, I'd
suggest that you read RFC 2616, Hypertext Transfer Protocol
(HTTP/1.1)[2] to be sure you behave properly (especially when sending
data from the server). You might also want to review Microsoft's
overview of processing user input in ASP[3]. Though it refers to forms
throughout, that's irrelevant in this case: the transmission method (GET
vs. POST) is key.
[snipped encoding question]
Hope that helps,
Mike
Copied and follow-ups set to microsoft.public.inetserver.asp.general
(NB. I don't read this board as I don't use ASP)
[1] <http://msdn.microsoft.com/en-us/library/ms525985(v=vs.90)>
[2] <http://www.w3.org/Protocols/rfc2616/rfc2616.html>
[3] <http://msdn.microsoft.com/en-us/library/ms525182(v=vs.90)>
--
Mike Winter
Replace ".invalid" with ".uk" to reply by e-mail.
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.javascript
csiph-web