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) defined abc 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 use addEventListener instead of onclick. – CherryDT Commented Mar 17, 2022 at 15:08
Add a ment  | 

2 Answers 2

Reset to default 1

Did 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

本文标签: