Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Christoph Becker Newsgroups: comp.lang.javascript Subject: Re: XMLHttpRequest: POST with Data Date: Fri, 24 Aug 2012 02:54:42 +0200 Organization: Aioe.org NNTP Server Lines: 68 Message-ID: References: <429d38h112ptste9sp22ks8sqk9cgumo7r@4ax.com> NNTP-Posting-Host: IbPwE7cK01o7JsfqwD6zIQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20120713 Thunderbird/14.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.javascript:15543 Gene Wirchenko wrote: > On Fri, 24 Aug 2012 01:11:40 +0200, Christoph Becker > wrote: > >> 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. >> >> If you send a POST request (without any additional query string), no >> query string will be sent (so .QueryString, which is supposedly .NET, >> will be empty). You have to look at some other >> property/variable/function (in PHP it would be $_POST). > > .QueryString is in Classic ASP (which is what I am using). I have no experience with ASP, but you might try Request.Form. > >>> 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? >>> >>> 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? >> >> For POST requests escaping on the client side should not be necessary. >> For GET requests encodeURI() resp. encodeURIComponent seem to be more >> appropriate. >> >> How to escape when sending data to the client depends. > > But what does it depend on? I get tired of guessing. I would > like to get it right. It depends heavily on the Content-Type you're sending (JSON, XML, HTML etc.) and the "technique" you're using to constructing the response. But anyway, this question might better be asked in an appropriate ASP newsgroup or forum. > > [snip] > > Sincerely, > > Gene Wirchenko > -- Christoph M. Becker