[jQuery] Re: Including the submit element in the querystring.

2008-07-01 Thread Mike Alsup

 Serialize is a great method to automatically prepare a form, but it
 doesn't include the element that initiated the submit in the case
 where I attach a click event to a div and call submit from the click
 event.

 Is there a typical pattern to adding the submit element to the
 serialized string so the server can know which element initiated?

 Does it matter what format it's in?  (submitter=elementId)?

 *bonus question*
 This is academic but I'm trying to learn: why does ajax put data in a
 querystring instead of using a form like normal html submit would do?

You could use the Form Plugin and its ajaxForm method if you want it
to be handled for you. Otherwise it's up to you to append the
submitting element's name and value to the data submitted.

$.ajax does submit data the same way as a normal http submit.  The
query string is added to the url for GET requests and put in the body
for POST requests.

Mike


[jQuery] Re: Including the submit element in the querystring.

2008-07-01 Thread Carl Von Stetten

By default, the jQuery.ajax (or $.ajax) function uses the get method, 
which passes the data as a querystring tacked onto the url.  So does the 
jQuery.get (or $.get) function.  This is the same as a form submitted 
using the get method. 

If you are using the $.ajax function, you can set the type option to 
post to have it submit as form data, or you can use the jQuery.post 
(or $.post) function.  Either way, it sends the data as form data (same 
as a form submitted using the post method.

HTH,
Carl



LTG wrote:
 Serialize is a great method to automatically prepare a form, but it
 doesn't include the element that initiated the submit in the case
 where I attach a click event to a div and call submit from the click
 event.

 Is there a typical pattern to adding the submit element to the
 serialized string so the server can know which element initiated?

 Does it matter what format it's in?  (submitter=elementId)?

 *bonus question*
 This is academic but I'm trying to learn: why does ajax put data in a
 querystring instead of using a form like normal html submit would do?

 best regards,
 ltg


   


[jQuery] Re: Including the submit element in the querystring.

2008-07-01 Thread LTG

Is there a place that explains the differences in functionality
between the core and the forms plugin?

I came across a 2006 thread where so many people supported adding the
functionality to the core that I just assumed it happened.

thanks for the reply,
ltg


On Jul 1, 5:03 pm, Mike Alsup [EMAIL PROTECTED] wrote:
  Serialize is a great method to automatically prepare a form, but it
  doesn't include the element that initiated the submit in the case
  where I attach a click event to a div and call submit from the click
  event.

  Is there a typical pattern to adding the submit element to the
  serialized string so the server can know which element initiated?

  Does it matter what format it's in?  (submitter=elementId)?

  *bonus question*
  This is academic but I'm trying to learn: why does ajax put data in a
  querystring instead of using a form like normal html submit would do?

 You could use the Form Plugin and its ajaxForm method if you want it
 to be handled for you. Otherwise it's up to you to append the
 submitting element's name and value to the data submitted.

 $.ajax does submit data the same way as a normal http submit.  The
 query string is added to the url for GET requests and put in the body
 for POST requests.

 Mike


[jQuery] Re: Including the submit element in the querystring.

2008-07-01 Thread Mike Alsup

 Is there a place that explains the differences in functionality
 between the core and the forms plugin?

 I came across a 2006 thread where so many people supported adding the
 functionality to the core that I just assumed it happened.

You're right, a good portion of the Form Plugin's functionality moved
into core. Specifically, the serialization capabilities.  But the core
lib doesn't provide the capability your asked about - detecting the
submitting element and adding it to the request data.  Basically, the
core can handle all of your serialization needs.  But if you want a
simple way to bind submit events and have forms auto-ajaxified then
the Form Plugin steps in to fill that role, and offers numerous
options as well.