admin管理员组文章数量:1391934
I am trying to use MYSQL NodeJS with BROWSERIFY and face this problem
HTML code
<button type="button" onclick="abc()" >xyz</button>
<script type="text/javascript" src="./bundle.js"></script>
connectdb.js code
function abc(){
con.connect(function(err) {
if (err) throw err;
con.query("SELECT * FROM database_nmcnpm_nhom1.users", function (err, result) {
if (err) throw err;
else
console.log(result)
});});}
I used browserify like this
browserify ./connectdb.js -o ./bundle.js
But when i click the button the console show error:
Uncaught ReferenceError: abc is not defined at HTMLButtonElement.onclick
Can someone please suggest a solution?
Thanks
I am trying to use MYSQL NodeJS with BROWSERIFY and face this problem
HTML code
<button type="button" onclick="abc()" >xyz</button>
<script type="text/javascript" src="./bundle.js"></script>
connectdb.js code
function abc(){
con.connect(function(err) {
if (err) throw err;
con.query("SELECT * FROM database_nmcnpm_nhom1.users", function (err, result) {
if (err) throw err;
else
console.log(result)
});});}
I used browserify like this
browserify ./connectdb.js -o ./bundle.js
But when i click the button the console show error:
Uncaught ReferenceError: abc is not defined at HTMLButtonElement.onclick
Can someone please suggest a solution?
Thanks
Share Improve this question asked Mar 17, 2022 at 15:00 Huu Tuong TuHuu Tuong Tu 231 gold badge1 silver badge5 bronze badges 1-
Just from the
});});}
at the end it seems as if you (or Browserify) definedabc
somewhere in a deeply nested scope and not in the global scope reachable from the HTML document's attributes. It would probably make more sense for you to useaddEventListener
instead ofonclick
. – CherryDT Commented Mar 17, 2022 at 15:08
2 Answers
Reset to default 1Did you include a reference to connectdb.js
in your HTML? If not, you'll have to add this to your HTML file:
<script type="text/javascript" src="./connectdb.js"></script>
I generally used to solve this issue as shown below
<button type="button" (click)="methodName()" > submit</button>
In Angular
本文标签:
版权声明:本文标题:javascript - Uncaught ReferenceError: <function> is not defined at HTMLButtonElement.onclick when use Browserify - 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744689047a2619879.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论