Page 1 of 1

ajax. submitting data. concept question

Posted: Mon Dec 11, 2006 9:55 am
by jmut
Hi,
Are you guys always submitting whole form data when using ajax...or just some fields necessary for the operation you want to perform?
Would it be wrong to submit whole form data?

As a result, comes the question on how to collect all form data and safely transfert it to php. I think JSON is key word here..but not sure.
while it is easy to itterate each form element using javascript....


What about trying to get array out of some var? Is this wrong and useless approach to try?

Code: Select all

<intput type='text' name='collection[]' />
Would greatly appreciate any comment on that.
Thanks

Posted: Mon Dec 11, 2006 10:42 am
by CoderGoblin
The Ajax Prototype script has form functionality.... Painless JavaScript Using Prototype Page 2. Whilst I realise that the library prototype is not for everyone... this is one solution if you want to send the whole form (doesn't work with upload as far as I can tell). Normally the function that calls Ajax gets the limited form information needed to fulfill the request.

You have to ask the question though, if you are handling large amouts of data, doesn't it make more sense to load the page again using php and if necessary Header(Location: nextpage) ? In general I only use Ajax for small things such as dynamic/chained selects/setting a SESSION variable containing bookmark numbers etc. In these cases the time the user has to wait for a response is minimal. If updating a major form the user commonly expects the page to reload.

Posted: Tue Dec 12, 2006 12:22 am
by jmut
well,
thats what I think... we are having a little dispute here with collegues.
They think that it makes no sense to send only part of form data....but rather send it all.
And they are trying to figure out how to collect and make ajax call from form fields like....

Code: Select all

<intput type='text' name='collection[]' value='n' />
Oh well...time will tell :)
Thanks for the article.