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


Groups > comp.lang.javascript > #36603

Re: AJAX form submitting question

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.javascript
Subject Re: AJAX form submitting question
Date 2019-05-13 13:45 +0100
Organization A noiseless patient Spider
Message-ID <871s12o74b.fsf@bsb.me.uk> (permalink)
References <731219e2-70a0-401c-a6ae-f11fe1191dbc@googlegroups.com>

Show all headers | View raw


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.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web