Click here to Skip to main content
15,901,853 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,
I have function as below
 $(document).on('click', '#btnVwProfl', function () {
                
    var result = $(this).parents('div[data-role="footer"]').siblings('.ui-grid-a').find('#lblempID').text();

    getOrgList(result);
    
    $.mobile.changePage("#divDetails", { transition: "slide", reloadPage: false, changeHash: true });
});


I want the changePage to be called after the function getOrgList() execution.

How can I achieve the same using jQuery?

How can we implement $.when().then() or $.when().done() to achieve the above?

I'm using 1.7-2 version of jQuery

Thanks in advance
Posted
Comments
Sampath Lokuge 14-Feb-14 1:30am    
Is this jQuery mobile app ?
dhage.prashant01 14-Feb-14 1:38am    
Yes

1 solution

I have passed one more parameter 'callback' to the function as follows:
function getOrgList(empno, callback) {
            var URL = "http://xxx.xx.xxx.xxx/ApprovalSystem/api/Organisation/getOrganisationChart";
            $.support.cors = true;

            $.mobile.loading('show', { text: "Getting Details..", textVisible: true, theme: "a" });

            userData.EmpDetails = new Array();
            userData.EmpDetails[0] = new Object({ EmpID: empno });

            $.ajax({
                url: URL,
                type: 'POST',
                data: JSON.stringify($.toJSON(userData)),
                contentType: "application/json;charset=utf-8",
                success: function (data) {
                    if (data.status == "true") {

                        buildChart(data);

                        $.mobile.loading('hide');

                        callback();
                    }
                    else {
                        $.mobile.loading('hide');
                        $('#divAlert').text(data.statusmessage);
                        $('#popupAlert').popup('open');
                        setTimeout(function () { $("#popupAlert").popup("close") }, 2000);
                    }
                },
                error: function (xhr, textStatus, err) {
                    $.mobile.loading('hide');
                    $('#divAlert').text("Request failed: " + err);
                    $('#popupAlert').popup('open');
                    setTimeout(function () { $("#popupAlert").popup("close") }, 2000);
                }
            });
        }


And in the place where function to be called, I have written below code
getOrgList(empno, function () {
                   $.mobile.changePage("#divDetails", { transition: "slide", reloadPage: false, changeHash: true });
               });


That's simple solution :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900