Patrioticcow
Patrioticcow

Reputation: 27058

jquery, how to trigger function from a button click?

i have this example:

<script>
$('.myvideos').live('click', function() {
    $('#myvideos').trigger('click');
    var ide = '123';
    function ajax_request() {
        $('#placeholder').load("test.php?id=ide");
    }
});
</script>

how can i trigger the ajax_request function after $('#myvideos').trigger('click'); happens and pass the ide var to load link?

any ideas? thanks

Upvotes: 2

Views: 1682

Answers (3)

ysrb
ysrb

Reputation: 6740

Try:

<script>
$('.myvideos').live('click', function() {
    var ide = '123';
    ajax_request(ide);
});

function ajax_request(ide) {
        $('#placeholder').load("test.php?id="+ide);
    }

</script>

Upvotes: 4

Oleg Grishko
Oleg Grishko

Reputation: 4281

You don't really have to put the AJAX call inside a function

<script>
$('.myvideos').live('click', function() {
    $('#myvideos').trigger('click');
    var ide = '123';
    $('#placeholder').load("test.php?id=" + ide);
});
</script>

Upvotes: 0

ValeriiVasin
ValeriiVasin

Reputation: 8726

<script>
  $('.myvideos').live('click', function() {
    var ide = '123';
    ajax_request(ide) 
  });

  function ajax_request(ide) {
    $('#placeholder').load("test.php?id=" + ide);
  }
</script>

Upvotes: 4

Related Questions