🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
In this post, I would suggest two ways to import the JQuery library into a TypeScript file.
Approach 1
If you have included jquery library somewhere in your project then below the line of code shows how to imported jquery in TypeScript file:import { $ } from '../jquery-3.1.1';
Approach 2
You can install jquery using npm and then import into a TypeScript file like this:
First, install jquery using the following command:
npm install @types/jquery --save-dev
Now, import jquery into import into a TypeScript file:
import * as $ from 'jquery';
Example: This approach worked for me and here is the sample usage of this:
import * as $ from 'jquery';
export class Login {
    static readonly PARAM_USERNAME = "j_username";
    static readonly PARAM_PASSWORD = "j_password";
    login(loginId, password, sdkURL) {
        let data = {
            PARAM_USERNAME: loginId,
            PARAM_PASSWORD: password
        }
        this.loginService(data);
    };
    logout(loginId) {
        //
    };
    private loginService(data: any) {
        console.log("inside ajax - data :: " + data);
        $.ajax({
            method: 'POST',
            url: 'URL Here',
            data: data,
            async: false,
            contentType: "application/x-www-form-urlencoded",
            dataType: "json",
            success: function (response) {
                console.log(JSON.stringify(response));
            },
            error: function (response, status, error) {
                console.log(JSON.stringify(response));
            }
        });
    }
}
 
 
 
![[NEW] Full-Stack Java Development with Spring Boot 3 & React Build 5 Spring Boot Projects with Java: Line-by-Line Coding](https://img-c.udemycdn.com/course/750x422/5338984_4d3a_5.jpg) 
 
 
 
 
 
 
 
 
 
 
Comments
Post a Comment
Leave Comment