Reputation:
Please help me why .done is not showing in intelligence and also its throughing an Error as Cannot read property 'done' of undefined
Jquery
$(document).ready(function () {
$('#BtnSubmit').click(function () {
var PromiseApi = CallingApi();
PromiseApi.done(function (data) {
alert(data.EmpName);
})
})
function CallingApi() {
$.ajax({
url: 'http://localhost:10948/Api/Home/GetEmployee',
contentType: 'application/x-www-form-urlencoded',
type:'GET',
})
}
})
Upvotes: 0
Views: 38
Reputation: 218877
This function doesn't return anything, so its return value is undefined
:
function CallingApi() {
$.ajax({
url: 'http://localhost:10948/Api/Home/GetEmployee',
contentType: 'application/x-www-form-urlencoded',
type:'GET',
})
}
Add a return statement to return the promise object:
function CallingApi() {
return $.ajax({
url: 'http://localhost:10948/Api/Home/GetEmployee',
contentType: 'application/x-www-form-urlencoded',
type:'GET',
})
}
Upvotes: 4