You can try like below.

i.e. make your ajax call async:false

$.ajax({
url: restmethod,
type: "POST",
contentType: "application/json",
async:false
success: function(data) {
    return data.d; 
}
});


I hope this will help to you.

How to combine 2 click function?
All is in the title: does IEEE-754 float, double and quad guarantee exact representation of -2, -1, -0, 0, 1, 2 ?
