ajax. submitting data. concept question

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

ajax. submitting data. concept question

Post 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
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post 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.
Post Reply