Monday, 8 May 2017

Error when I try to connect my site to MySql DB with node.js

This is the error:

Uncaught Error: Mismatched anonymous define() module: function (){return __e}
http://requirejs.org/docs/errors.html#mismatch
    at makeError (require.js:417)
    at intakeDefines (require.js:1503)
    at require.js:1701
require.js:2420 XMLHttpRequest cannot load file:.../Slide_upload/mysql.js. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
require.load @ require.js:2420
require.js:417 Uncaught Error: Load timeout for modules: mysql
http://requirejs.org/docs/errors.html#timeout
    at makeError (require.js:417)
    at checkLoaded (require.js:947)
    at require.js:968

This is part of my html code:

<!DOCTYPE html>
<html lang="it">

<head>
    <meta charset="utf-8">
    <title>Slide Uploader</title>

    <!-- Google Fonts -->
    <link href='https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700|Lato:400,100,300,700,900' rel='stylesheet' type='text/css'>


    <link rel="stylesheet" href="css/style.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="js/sweetalert2.min.js"></script>
    <link rel="stylesheet" href="css/sweetalert2.min.css">
    <script src="js/slide_upload.js"></script>
    <script src="js/require.js"></script>
    <script src="js/insert.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.js"></script>
</head>

Finally is insert.js code:

require(["mysql"],function(mysql){
       var connection = mysql.createConnection({
           host: 'loaclhost',
           user: 'root',
           password: 'root',
           database: 'slide_uploader'
        });

    connection.connect(function(err){
            if(err){
                console.log("Error connecting to DB");
                return;
            }
            console.log("Connection Established");
     });
}); 

I have followed various tutorials to write the code of insert.js but I would not know how to solve (i have both node.js, npm, mysql installed)



via jLab19

No comments:

Post a Comment