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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:36:48+00:00 2026-06-12T18:36:48+00:00

I want to submit a form without refreshing the page, and I have this

  • 0

I want to submit a form without refreshing the page, and I have this form:

<form method="post" action="user-add.php" id="user-add-form">
<input type="text" id="username" name="username" maxlength="15">
<button type="submit" name="add_user" class="btn btn-primary" id="user-add-submit">Add user</button>
</form>

and this jquery function ( using jquery validation plugin ):

submitHandler: function() {

    $('#user-add-submit').button('loading');

    var post = $('#user-add-form').serialize();
    var action = $('#user-add-form').attr('action');

    $("#message").slideUp(350, function () {

        $('#message').hide();

        $.post(action, post, function (data) {

            $('#message').html(data);
            $('#message').slideDown('slow');

            if (data.match('success') !== null) {
                $('#user-add-form input').val('');
                $('#user-add-submit').button('reset');
            } else {
                $('#user-add-submit').button('reset');
            }
        });
    });
}

But my question is what user-add.php should look like for the script to work?

  • 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-12T18:36:50+00:00Added an answer on June 12, 2026 at 6:36 pm

    You callback function answers this question itself:

    function (data) {
        $('#message').html(data);  // #1
        $('#message').slideDown('slow');
    
        if (data.match('success') !== null) {  // #2
            $('#user-add-form input').val('');
            $('#user-add-submit').button('reset');
        } else {
            $('#user-add-submit').button('reset');
        }
    }
    
    • It has to return HTML, because the result goes directly into the DOM (#1)
    • The HTML has to contain (or not contain) the case-sensitive substring “success” depending on how the operation concluded (#2)

    The above holds if we assume that the function will not be modified. But it would be a good idea to modify the function to make it more computer-friendly. You could instead return some JSON that looks like this:

    {
        html: "the HTML for your page goes here",
        successful: true
    }
    

    Here html is what you want to show and successful is for internal consumption. This way you don’t have to couple the string "success" with determining if the operation was successful indeed. With this scheme your callback would look like this:

    function (json) {
        $('#message').html(json.html);  // #1
        $('#message').slideDown('slow');
    
        if (json.successful) {
            $('#user-add-form input').val('');
            $('#user-add-submit').button('reset');
        } else {
            $('#user-add-submit').button('reset');
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm at http://www.domain.com/page.html . I want to submit this form: <FORM METHOD=post
I have the following working form: <div id=player_won> <form action=insert.php method=post> Firstname: <input type=text
Let's say I have this form : <form action=Change-status.php method=post> <select class=changeStatus name=changeStatus> <option
<form action =/submit-page/ method='post' class=editable> <fieldset> <select name=status id='status'> <option value=Submitted>Submitted</option> <option value=Canceled>Canceled</option> <option
I want to be able to post the following form without the page refreshing
I want to submit a form without page refresh using jQuery. I found some
I want to submit a form like this: <input type=button onclick=$('#form1').submit(); value=Create /> but
I want to submit search query form & get search result without redirecting/reloading/refreshing on
Any way to submit a form without refreshing the current page at all using
I am using php/ajax to submit a form without page refresh. Here are my

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.