Excel Addin Javascript code not working Using Visual Studio Code but works using Script Lab

Fritz Praus 1 Reputation point
2021-02-23T03:15:18.077+00:00

I have been using Script lab to build a prototype javascript excel addin. Now that the routines are working I am trying to use Visual Studio code to build the addin. I have transferred my working code to VS Code, the problem that I am having is an ajax call that works in Script Lab but is not in VS Code. Unfortunately I have not been able to get the debugger to work(thats a whole different topic) so I have no idea where the call is failing. I was wondering if I am forgetting something in the VS Code project settings. Any suggests would be greatly appreciated.

this is the call to the function:

usdCost = await doAjax("USD", rowRange.values[0][3], rowRange.values[0][4]);

this is the function that works in Script Lab but not VS Code:

async function doAjax(target, base, amount): Promise<number> {
let data;
let api_key = "c8d7266f9153c19fcbc4";
var url =
"https://free.currconv.com/api/v7/convert?q=" +
target +
"" +
base +
"," +
base +
"
" +
target +
"&compact=ultra&apiKey=" +
api_key;
try {
data = await $.ajax({
url: url,
data: {
format: "json"
},
dataType: "jsonp",
type: "GET"
});
var reverse_rate = data[base + "_" + target];
var convResult = amount * reverse_rate;
return Promise.resolve(convResult);
} catch (error) {
console.error(error);
}

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
942 questions
{count} votes