Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #36600 > unrolled thread

AJAX form submitting question

Started bygroovee@cyberdude.com
First post2019-05-13 04:25 -0700
Last post2019-05-14 02:21 +0700
Articles 4 — 3 participants

Back to article view | Back to comp.lang.javascript


Contents

  AJAX form submitting question groovee@cyberdude.com - 2019-05-13 04:25 -0700
    Re: AJAX form submitting question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-05-13 13:45 +0100
      Re: AJAX form submitting question groovee@cyberdude.com - 2019-05-13 07:20 -0700
    Re: AJAX form submitting question JJ <jj4public@vfemail.net> - 2019-05-14 02:21 +0700

#36600 — AJAX form submitting question

Fromgroovee@cyberdude.com
Date2019-05-13 04:25 -0700
SubjectAJAX form submitting question
Message-ID<731219e2-70a0-401c-a6ae-f11fe1191dbc@googlegroups.com>
I wanted to know how to submit a form using AJAX, ie. without a refresh, searching took me to this page:

https://www.sitepoint.com/community/t/ajax-onsubmit-form-not-working/29367/6

I can't understand and have a question about post #6. In the beginning of the JS code, there is this:

   function ajaxFunction(e){
        e.preventDefault();
       blah blah

, but right at the end, when "ajaxFunction" is actually CALLED, it's like this:

   f.onsubmit = ajaxFunction;

ie. WITHOUT AN ARGUMENT! So where does the "e" come from then, when the function is called?


Thanks for your help.

[toc] | [next] | [standalone]


#36603

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2019-05-13 13:45 +0100
Message-ID<871s12o74b.fsf@bsb.me.uk>
In reply to#36600
groovee@cyberdude.com writes:

> I wanted to know how to submit a form using AJAX, ie. without a
> refresh, searching took me to this page:
>
> https://www.sitepoint.com/community/t/ajax-onsubmit-form-not-working/29367/6
>
> I can't understand and have a question about post #6. In the beginning
> of the JS code, there is this:
>
>    function ajaxFunction(e){
>         e.preventDefault();
>        blah blah
>
> , but right at the end, when "ajaxFunction" is actually CALLED, it's like this:
>
>    f.onsubmit = ajaxFunction;

That's not a call.  That just sets up what function /will/ be called if
and when a 'submit' event occurs.

You should probably read up on event handlers because they all rely on
the same basic pattern: the programmer simply says what function to call
when the events occurs although this is usually done using a call to
addEventListner these days.

> ie. WITHOUT AN ARGUMENT! So where does the "e" come from then, when
> the function is called?

When the event occurs (in this case a submit event), the handler
function (in this case ajaxFunction) is called with the event as the
argument.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#36604

Fromgroovee@cyberdude.com
Date2019-05-13 07:20 -0700
Message-ID<1e66b462-4bab-493a-9fb5-5d54f523b692@googlegroups.com>
In reply to#36603
On Monday, 13 May 2019 18:15:46 UTC+5:30, Ben Bacarisse  wrote:

> 
> That's not a call.  That just sets up what function /will/ be called if
> and when a 'submit' event occurs.

Oops! Sorry, I should have said "when the handler is actually DEFINED" (I *do* KNOW that...).


> 
> > ie. WITHOUT AN ARGUMENT! So where does the "e" come from then, when
> > the function is called?
> 
> When the event occurs (in this case a submit event), the handler
> function (in this case ajaxFunction) is called with the event as the
> argument.

AH thanks, I did not know that :)

[toc] | [prev] | [next] | [standalone]


#36608

FromJJ <jj4public@vfemail.net>
Date2019-05-14 02:21 +0700
Message-ID<krdtgeaytu2m.7d30cwvcrlm3$.dlg@40tude.net>
In reply to#36600
On Mon, 13 May 2019 04:25:06 -0700 (PDT), groovee@cyberdude.com wrote: 
> I wanted to know how to submit a form using AJAX,

See below guide.

<https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web