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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:44:14+00:00 2026-05-20T22:44:14+00:00

I want to send one of two async requests based on a click event

  • 0

I want to send one of two async requests based on a click event (login and register).
My click handler is sending 2 POST requests for each respective click (2 login requests, or 2 register requests). I know that event handlers created by the live method can cause this problem. The thing is, I don’t have any in my script. I’ve replaced them with .delegate()

Here it is…

 //ajax registration.  
$('input#register_submit').click(function(event){
    $.post("/register_async/", $('div#register_side form').serialize(), 
        function(data){
            $.each(data,function(){
            if(this.user_status==1){
                $('#header-top').html('<ul><li>Hi,'+ this.user_fname + '&nbsp | </li><li><a href="">Log Out</a></li></ul>');
                $('#post_login_modal').dialog("close");

                $('input[name=preview]').unbind('click');

                $('a.login').unbind('click');
                $('li a.account').unbind('click');  

            }
            else{
                 $('p#login_title').text('There are errors in your form').css("color","red");

            //redirect upon failed registration
            //window.location='{{site}}register';

            }
        });         
        }
    ,'json');
    event.stopPropagation();
    return false;
    });


//ajax login...just for this page right now  
$('input#login_submit_btn').click(function(event){
    $.post("/login_async/", $('div#login_side form').serialize(), 
        function(data){
            $.each(data,function(){
            if(this.user_status==1){
                $('#header-top').html('<ul><li>Hi,'+ this.user_fname + '&nbsp | </li><li><a href="">Log Out</a></li></ul>');
                $('#post_login_modal').dialog("close");

                $('a.login').unbind('click');
                $('li a.account').unbind('click');

                //specific to upload page.  removes login/register modal window click handler
                $('input[name=preview]').unbind('click');

                $('#contact_btn').unbind('click');
                $('#contact_btn').click(function(){
                $('#contact_renter').dialog('open');
                    });

                $('#save_btn').unbind('click');
                $('#save_btn').click(function(){
                    $('#save_modal').dialog('open');
                });


                $('span.anon').unbind('click');
                $('li.star_rater span.last').click(function(e){
                    $('#rate_modal').dialog('open');
                    e.stopPropagation();

                $('#flag span').click(function(event){
                    $('#rate_modal').dialog('close');
                    $('#flag_modal').dialog('open');
                    event.stopPropagation();

                });     

                //change rating/reporting, saving favorites, and contact based on ajax response 

            });

            }
            else{
                $('p#login_title').text('That email/password is invalid').css("color","red");
            }
            //prevents user from saving post as favorite if he has already done so
            if(this.user_favorite==1){
                $('#stats li:eq(3)').remove();
                $('<li><span id="saved">Saved<span></li>').appendTo('ul#stats');
            };  
            //prevents user from rating/reporting more than once
            if(this.flag_record==1){
                $('.star_rater span.anon').remove();
                $('<span class="voted"> Rated! </span>').appendTo('li.star_rater');
            };  

        });
    },'json');
    return false;
    });

To deal with closing all modal windows throughout my site, I also have this event handler:

   $('body').delegate(".ui-widget-overlay","click", function(e) {
$("#rate_modal,#contact_renter,#save_modal, #login_modal,#post_login_modal,#flag_modal,#save_success,#flag_success,#mail_success,#rating_success,#delete_note").dialog("close");
e.stopPropagation();
});

I could have sworn, after I changed the live handler to delegate, it worked.

  • 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-20T22:44:14+00:00Added an answer on May 20, 2026 at 10:44 pm

    I don’t know why I didn’t think of this before. If those click handlers are attached to <input type="submit"> buttons, then you’re submitting the forms twice: once for the click events, through AJAX, and again through the onsubmit events of the forms.

    Change your .click() functions to .submit() and attach them to the form elements rather than the submit buttons.

    $('form#form1').submit( function() {
        // your existing code
        return false;
    }
    

    Either that, or change those submit buttons into actual <button>s, or <a>s, or something.

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

Sidebar

Related Questions

I want to send mail to clients with two information, one is event for
In my application i want send a email to one account.in one button click
I want to send more than one image file from client to server for
Let's say I want to send a message from one client to another. How
I need your help with this one again. I want to send special characters
I have text files with one source and two destination path..I'm sending those to
I have two text boxes and i want to send these two text box
Actually i am developing tracking app and want to send Location updates between two
I have two radio buttons, and depending on which one is selected I want
I have two C# programs and I want to send some data back and

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.