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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:07:29+00:00 2026-05-23T04:07:29+00:00

I want to trigger this function, which uses the jquery’s post method, when a

  • 0

I want to trigger this function, which uses the jquery’s post method, when a form is submitted:

function update_point_session(){
    $.post('/update_point_session/', 
           {session: true},
           function(data){}
    );
    return true;
}

I uses the onsubmit to trigger it.

The problem is that it won’t send it when the form is submitted. But if I return false; it will (though the form itself, of course, will not). It looks as if the $.post is not send before the page is directed to another one by the form..

So I think I somehow have to return true; AFTER the $.post. I tried to do this by putting it inside function(data){} but it did not work..

How can I send BOTH the post from jquery and from the form?

  • 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-23T04:07:29+00:00Added an answer on May 23, 2026 at 4:07 am

    There are a couple of things you can do.

    Make the AJAX synchronous

    Since $.post is, according to the documentation, equivalent to

    $.ajax({
        type: 'POST',
        url: url,  
        data: data,
        success: success  
        dataType: dataType
    });
    

    You can simply replace $.post with the equivalent $.ajax call, and also add async: false to the options. This will submit the form with AJAX and then, due to the return true; from the function, will also let the browser post the form normally.

    Submit the form only after the AJAX completes

    This involves some event handler juggling:

    // attach submit event handler to the form
    $("#myform").submit(function() { 
        // Handler immediately detaches itself, so that
        // we don't have an infinite loop when we call
        // $(this).submit() ourselves below
        $(this).unbind('submit');
    
        // Do the AJAX
        $.post(
            '/update_point_session/', 
            {session: true},
            function(data){
                // When the AJAX completes, tell the browser
                // to re-submit the form
                $(this).submit();
            }
        );
    
        // Prevent the browser from submitting it NOW,
        // because the AJAX is still running
        return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I want to trigger an error in my interpreter I call this function:
I want to trigger the click, to which following code is listening: chrome.browserAction.onClicked.addListener(function(tab) {});
This is my jQuery script: $(input[type=radio]:checked).live(click, function() { $(this).attr(checked,false); }); I want to make
In jQuery, I do stuff like this a lot: $('#myId').bind('myevent', function() { ... }).trigger('myevent');
I want to trigger on click of a button this: <asp:Button runat=server ID=submit Text=Submit
I want to trigger a hyperlink by hitting Enter using jQuery. I have the
I want to trigger a special action in the save() method of a Django
Short version: I want to trigger the Form_Load() event without making the form visible.
I often want to trigger a certain function just once, but I need to
Possible Duplicate: jquery trigger - ‘change’ function I have a radio button set called

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.