Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6613449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:13:12+00:00 2026-05-25T20:13:12+00:00

I am reading the documentation on the jQuery website about the $.ajax() method and

  • 0

I am reading the documentation on the jQuery website about the $.ajax() method and I didn’t see an example of the HTML. I’m wondering how you tie the $.ajax() function to a user’s “Click” on the submit button. This is my best guess, is it the right way?

Here is the example:

<html>
<head></head>
<body>
<form id="my_form">
<input type="text" name="name"><br />
<input type="text" name="email"><br />
<textarea name="message"></textarea>
<input type="submit" name="submit">
</body>
</html>

Javascipt

submit: function {
var form_data = $("form#my_form").serialize();

function progress() {
    //some loading gif
};

function removeProgress() {
    //remove the loading gif
};
$.ajax ({

    type: "GET",
    url: "contact-us.php",
    data: form_data,
    beforeSend: progress(),
    error: function() { alert("dude, something went wrong!"); },
    success: function() { alert("WIN!"); },
    complete: function() { 
        removeProgress();
        alert("1 row added."); 
    }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:13:12+00:00Added an answer on May 25, 2026 at 8:13 pm

    You will need to bind the function to an event triggered by an element. For example, to bind a function to the submit event of the <form id="my_form"> element, you would do this:

    $(document).ready(function () {
        // ..
        $('#my_form').submit(function (event) {
            // ajax call here
        });
    });
    

    In order to prevent the form from posting to a page (as it would normally do), you would need to add a call to preventDefault() on the event, like this:

    $(document).ready(function () {
        // ..
        $('#my_form').submit(function (event) {
            // ajax call here
            event.preventDefault();
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to HTML. When I started reading documentation about lists, I've noticed that
I'm using jQuery in my web application. While reading its documentation I read about
Reading through the jQuery documentation about the event object and its constructor $.Event() I
I have always used the mouseover event, but while reading the jQuery documentation I
When reading some documentation about assertions, I found: java -ea -dsa Enables assertions in
I'm reading the jQuery load documentation and it mentions that I can use load
After reading about valHooks in a jQuery defect and more recently seen in a
I was reading the jQuery UI API for datepicker. The example code has something
I've been reading the documentation of a jQuery Validation Plugin and for some reason
I'm reading the documentation here: jQuery, Waypoints, plugin docs . And I'd like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.