I recently added jQuery typings to my TypeScript project. I am able to type $.ajax(...) without encountering any compile errors in VS Code. However, when I test it on localhost, I receive an error stating that "$ is not defined." In an attempt to address this issue, I tried importing jQuery using the following syntax:
import * as jQuery from "jquery"
I followed a similar method to import express, and it worked successfully.
In VS Code, when I begin typing "jquery.", the editor suggests "ajax" as a method, indicating recognition of my import. Despite this, upon testing on localhost again, I am informed that jquery.ajax is not a function.
This is how I structured my test ajax call:
jquery.ajax("test.html", {
success: function () {
alert("success");
},
error: function () {
alert("error");
}
});
How can one properly execute an ajax call with jQuery in TypeScript?