简体   繁体   中英

$ is not defined - Ajax call in external js file

I'm trying to execute a JavaScript function. I get an error everytime the function enters the Ajax block saying:

$ is not defined

How can I solve this problem? I'm Programming a Google Chrome Addon and I get this error in my .js file:

在此处输入图片说明

At the moment ther is just the function above and its caller in the file:

// Calls get_pw function
document.addEventListener('DOMContentLoaded', function(){
    document.getElementById('submit').addEventListener('click', get_pw)
})

Many Thanks

Include jQuery before executing the function or rewrite AJAX request without jQuery.

Including can be done simply by copying jQuery code at the beginning of your script or by loading a file from their CDN and then executing your script on a callback (slower).

Download jQuery from https://code.jquery.com/jquery-3.3.1.min.js . Include it in head tag of your document and call get_pw() when document has loaded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM