Recently, I started learning about typescript and ajax. One of the challenges I encountered was while creating a method in typescript for making ajax calls that can be used across classes:
myFunc(value: string): JQueryPromise<any>
{
var dfd = $.Deferred();
$.ajax({
url: "http://finance.google.com/finance/info?client=ig&q=NASDAQ:GOOGL",
data: "",
success: function(response?: string) {
console.log("success");
dfd.resolve(response);
},
type: "GET",
async: true,
dataType: "jsonp"
});
return dfd.promise();
}
However, I faced an issue when trying to consume this method using when
and then
functions of jquery
var promiseOne = this.myFunc("value1");
$.when(promiseOne).then((valFromPromiseOne: any) =>
{
alert(valFromPromiseOne);
});
An error occurred in typescript indicating:
Supplied parameters do not match any signature of call target
If anyone could suggest the most effective way to retrieve results from my ajax method...I have attempted with jquery deferred as well but experienced the same issue.