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

  • Home
  • SEARCH
  • 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 6695861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:16:22+00:00 2026-05-26T06:16:22+00:00

I am trying to post a form using ajax. Right now, the code I

  • 0

I am trying to post a form using ajax.

Right now, the code I have is

$("#sub").click(function() {     
    var tag = $("#tagbar").val();
    var opinion = $("#op").val();
    alert($("#expressform").serialize());
    $.post("dbfunctions.php", $("#expressform").serialize());
});

This works, but it takes a long time to post and add to the database (thats what dbfunctions does) compared to how long it took before, when I was using a form action and refreshing the page. Why is this?

Also, if I remove the alert, the script stops working completely. I can’t figure out anyway in which this makes sense.

Thanks

  • 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-26T06:16:23+00:00Added an answer on May 26, 2026 at 6:16 am

    Make sure you cancel the default action of the button by returning false from the click handler:

    $("#sub").click(function() {     
        $.post("dbfunctions.php", $("#expressform").serialize());
        return false;
    });
    

    Also instead of subscribing for submit button clicks, it’s better to subscribe to the submit event of the corresponding form directly:

    $("#expressform").submit(function() {     
        $.post(this.action, $(this).serialize());
        return false;
    });
    

    This way you are no longer hardcoding any urls in your javascript files. You are simply unobtrusively AJAXifying your form.

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

Sidebar

Related Questions

I am trying to submit a form using jQuery's .ajax() function. It seems like
I am trying to submit a form using Ajax.Updater and have the result of
I'm trying submit some form using ajax //include jquery-1.4.2.min.js var submitForm = document.createElement(FORM); ...
I have a login form using jquery ajax and a php code. The issue
I am trying to post a multi-part form using httplib, url is hosted on
I am trying to get some form data from POST method. Here's the code
I'm trying to access the post target action in a jquery function. example: <form
I'm stuck: I'm trying to submit a form using AJAX, but I can't find
so currently using ajax with JQuery .post to return a form populate with some
I'm using the following code in my HTML form - trying to make a

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.