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 8929631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:42:58+00:00 2026-06-15T08:42:58+00:00

I have an ajax submit that wouldn’t run no matter what I tried. That

  • 0

I have an ajax submit that wouldn’t run no matter what I tried. That is until I found a tutorial that had the submit wrapped in a $(function () {}); call. I then wrapped my .submit in a function call and it seemed to have worked. The thing that boggles my mind is that I have other .submit ajax function calls that work just as well without being wrapped in a function. I am wondering if I am missing a jQuery nuance here that I don’t understand?

To more fully illustrate what I mean, here is my function before and after I wrap it in a function…

Before…

$("#FormPutMsg1").submit(function (e) {
    debugger;
    e.preventDefault();
    //animateSpinner();
    var theURL = this.action;
    var type = "POST";//this.methd;
    var data = $(this).serialize();
    $.ajax({
        url: this.action,
        type: this.method,
        data: $(this).serialize(),
        dataType: "json",
        success: function (result) {
            debugger;
            var data = result;
            if (data.split(':')[0] == "Error") {
                //$("#list").unblock();
                $('#resultDiv').html('<b><p style="color: #ff00ff">' + data + '</p></b>');
                setTimeout(function () {
                    $('#resultDiv').html("");
                }, 10000);
            }
            else {
                binddata(data);
            }
        }
    });
    return false;
});

After (this one works)…

$(function () {
    $("#FormPutMsg1").submit(function (e) {
        debugger;
        e.preventDefault();
        //animateSpinner();
        var theURL = this.action;
        var type = "POST";//this.methd;
        var data = $(this).serialize();
        $.ajax({
            url: this.action,
            type: this.method,
            data: $(this).serialize(),
            dataType: "json",
            success: function (result) {
                debugger;
                var data = result;
                if (data.split(':')[0] == "Error") {
                    //$("#list").unblock();
                    $('#resultDiv').html('<b><p style="color: #ff00ff">' + data + '</p></b>');
                    setTimeout(function () {
                        $('#resultDiv').html("");
                    }, 10000);
                }
                else {
                    binddata(data);
                }
            }
        });
        return false;
    });
});

Before I wrapped my function in a function the regular submit functionality prevaled (because e.preventDefault was never called I presume). Am I missing something gentlemen (and ladies)?

  • 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-06-15T08:42:59+00:00Added an answer on June 15, 2026 at 8:42 am

    The original code block will never got executed because “#FormPutMsg1” wont yet exist. The second code block is executed after the page has been loaded so “#FormPutMsg1” would exist.

    $(“#FormPutMsg1”).submit() requires a trigger for it be executed. Wrapping it with “$(function() {})” will execute the block on page load. You could also trigger it using a click’ event.

    “$(function() {})” is a shortcut for “$(document).ready(function() {})”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Ajax form that updates a div when submitted with a submit
I have a page with multiple forms that I submit via Ajax POSTs serially.
I have tried to replace the submit button of a form with an ajax
I have a jQuery ajax function and would like to submit an entire form
I have a dynamically generated form that I would like to submit using Ajax.
I have an ajax form that I would like to submit, and the response
I have a basic form that I would like to submit using ajax, without
I have a script that submits data via an ajax POST. It is called
Possible Duplicate: jQuery AJAX submit form I have a form on a page A,
I have a strange error where my jquery ajax request doesn't submit all the

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.