You are calling MyFunction before it has been defined, so move to call to after it has been defined.
function myfunction() {
var objTask = {
SenderID: parseInt(sessionStorage.getItem('UserID'))
}
var pass =[];
$.ajax({
type: "POST",
url: "http://localhost:49534/TaskManagement.svc/TaskList",
data: JSON.stringify(objTask),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data, status, jqXHR, result) {
debugger;
for (i = 0; i < data.length; i++) {
pass.push ({"title": data[i].TaskName});
}
}
});
alert("Loding...");
return pass;
}
var Even = myfunction();