HighDots Forums  

why adds whitespace to data sent with ajax?

Javascript JavaScript language (comp.lang.javascript)


Discuss why adds whitespace to data sent with ajax? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Igal
 
Posts: n/a

Default why adds whitespace to data sent with ajax? - 12-15-2007 , 04:38 AM






i just started working with ajax, and werid thing happens.
i have a function that build my post string for ajax to send. it looks
like this:

function buildPOST(formName, formTask) {
theForm = document.getElementById(formName);
var qs = ''
for (e=0;e<theForm.elements.length;e++) {
if (theForm.elements[e].name!='' && theForm.elements[e].type !
= 'button' && theForm.elements[e].type != 'submit') {
var name = theForm.elements[e].name;
qs+=(qs=='')?'':'&'
qs+= name+'='+escape(theForm.elements[e].value);
}
}
if (formTask != null) { qs+="&task="+formTask; }
qs+="\n";
return qs
}

and this how i send it...
var postString = buildPOST(...);
....
xmlHttp.send(postString);

i have noticed that when i us $_POST['task'] with PHP (the last var in
the line) its actually that data + whitespace, so i need to do
trim($_POST['task']), question is why this happens? i don't think it's
the buildPOST func, since i tried tirming befor sending with ajax.

Reply With Quote
  #2  
Old   
VK
 
Posts: n/a

Default Re: why adds whitespace to data sent with ajax? - 12-15-2007 , 09:20 AM






On Dec 15, 1:38 pm, Igal <igal.al... (AT) gmail (DOT) com> wrote:
Quote:
function buildPOST(formName, formTask) {
theForm = document.getElementById(formName);
var qs = ''
for (e=0;e<theForm.elements.length;e++) {
if (theForm.elements[e].name!='' && theForm.elements[e].type !
= 'button' && theForm.elements[e].type != 'submit') {
var name = theForm.elements[e].name;
qs+=(qs=='')?'':'&'
qs+= name+'='+escape(theForm.elements[e].value);
}
}
if (formTask != null) { qs+="&task="+formTask; }
qs+="\n";
return qs

}

and this how i send it...
var postString = buildPOST(...);
...
xmlHttp.send(postString);
For crying out loud... No, I don't know why extra space, just use the
many years tested http://www.ajaxtoolbox.com for manual POST
submittal. See http://www.ajaxtoolbox.com/request/examples.php for
"Form Submittal" demo. As a small payback could you tell me why are
doing manually something what any single browser on the market does
automatically and reliably? I am just getting really curious.


Reply With Quote
  #3  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: why adds whitespace to data sent with ajax? - 12-16-2007 , 11:48 AM



Igal wrote:
Quote:
function buildPOST(formName, formTask) {
[...]
qs+="\n";
return qs
}

and this how i send it...
var postString = buildPOST(...);
...
xmlHttp.send(postString);

i have noticed that when i us $_POST['task'] with PHP (the last var in
the line) its actually that data + whitespace, so i need to do
trim($_POST['task']), question is why this happens? i don't think it's
the buildPOST func, since i tried tirming befor sending with ajax.
Since you have not posted how you try to trim the data to be submitted
before the request, it is likely that the additional unnecessary "\n" causes
this in PHP.

Please use a spell-checker, learn enough English to write something easily
understandable yourself, or try a local newsgroup next time instead.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7 (AT) news (DOT) demon.co.uk>


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.