1

I'm new to jQuery. I have this button #sess_s which should execute three click handlers. It works fine usually, but sometimes it will miss one or two click handlers. I want all three to work together when clicked. Any easy way? Thanks.

My code:

$('#sess_s').click(function() {
    $.post('sdata.php',{id_value: id_form.id_data.value  },
           function(output) {
               $('#sess_feed').html(output).show();
           });
});

$('#sess_s').click(function() {
    $.post('ssdata.php',
           function(output) {
               $('#sess_feed1').html(output).show();
           });
});

$('#sess_s').click(function() {
    $.post('ses_count.php',
           function(output) {
               $('#ses_count').html(output).show();
           });
});
3
  • Are you allowed to use .post as a variable name? What happens if you change the name to something like postClass? Commented Jul 29, 2011 at 15:20
  • I think that's actually a built in ajax call using jquery, @sunny. Commented Jul 29, 2011 at 15:22
  • @Andrew Peacock $.post is a function of the jQuery framework. Commented Jul 29, 2011 at 15:34

3 Answers 3

4
 $('#sess_s').click(function() {
        $.post('sdata.php',{id_value: id_form.id_data.value  },
           function(output) {
           $('#sess_feed').html(output).show();
        });

        $.post('ssdata.php',
           function(output) {
           $('#sess_feed1').html(output).show();
        });


        $.post('ses_count.php',
           function(output) {
           $('#ses_count').html(output).show();
        });


 });
Sign up to request clarification or add additional context in comments.

Comments

2

you can combine them:

$('#sess_s').click(function() {
    $.post('ssdata.php', function(output) {
        $('#sess_feed1').html(output).show();
    });
    $.post('ses_count.php', function(output) {
        $('#ses_count').html(output).show();
    });
    $.post('sdata.php', {
        id_value: id_form.id_data.value
    }, function(output) {
        $('#sess_feed').html(output).show();
    });
});

Comments

2

Try to attach one event handler but put all three code blocks inside one function:

Something like this:

$('#sess_s').click(function() {
    $.post('sdata.php'...
    $.post('ssdata.php'...
    $.post('ses_count.php'...
});

This is simplified, of course. You might want to wrap up every block with try/catch in case one fails...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.