views:

84

answers:

2

I want execute below callback() method after completion of document.getElementById('btnDownload').click(); method . Now callback()executing immediatly. I want wait "Click()" process done then Execute callback(); method.

function LoadPopup() {
        //  find the popup behavior
        this._popup = $find('mdlPopup');
        // show the popup
        this._popup.show();

        // synchronously run the server side validation ...
        document.getElementById('btnDownload').click();
       callback();         
    }

 function callback() {
        this._popup = $find('mdlPopup');
        //  hide the popup
        this._popup.hide();
        alert("hi");

}

+1  A: 

Unless I've wildly misunderstood the question, this code will make a request to the page that the link leads to, and when the server has returned the response, executes the function:

$(document).ready(function() {
  $("#btnDownload").click(function() {
    $.ajax({
      url: $(this).attr("href"),
      complete: function(xhr, status) {
        callback();
      }
    });
    return false;
  });
});

I may have wildly misunderstood the question...

GlenCrawford
A: 

Your question is not clear. But I will give you a example.

For example, you wan to load a page by clicking on a image then after the page load is complete you want to do something you can something like this

$('#buttonid').click(function() {
    //this is the callback function of click event
    //if you want some other callback functions then you need something like this
    $("#somediv").load("page.php", function() {
       //callback function code of .load event
       alert('page loaded');
       });
 });

What you are asking is to have a callback function inside the default callback function of click event and a bit impossible from my point of view.

Starx