Skip to content Skip to sidebar Skip to footer

Can't Include External Javascript In File

I'm new to PHP and VERY, VERY new to any sort of server administration. I'm running from XAMPP 3.1.0 for Windows and using PHP Version 5.4. My PHP script is executing just fine, bu

Solution 1:

After seeing your screenshots,

  1. When you use a src="" attribute, you are supposed to leave the body of the <script> tag empty. So remove that alert("I am here, aren't you!") from there.
  2. Your core.js is not found at the path. Let us know the folder path.

Solution 2:

  • Check your console for errors (CTRL+SHIFT+I for Chrome/Windows).
  • It's possibly a 404 error or an error in your core.js file. Make sure the path is correct: <script type="text/javascript" src="/path/to/core.js"></script>

  • The script is possibly being included too early/late. To test this, make sure that <script> block is in the <head>


Solution 3:

It was a simple coding error. I declared my namespace as a function instead of an object literal. The code should have read:

var Core = {
    namespace: function(ns){
        var parts = ns.split("."),
        object = this,
        i, len;
        for (i=0, len=parts.length; i < len; i++) {
            if (!object[parts[i]]) {
                object[parts[i]] = {};
            }
            object = object[parts[i]];
        }
        return object;
    }
};

Instead of:

var Core = function () {
    namespace: function(ns){
        var parts = ns.split("."),
        object = this,
        i, len;
        for (i=0, len=parts.length; i < len; i++) {
            if (!object[parts[i]]) {
                object[parts[i]] = {};
            }
            object = object[parts[i]];
        }
        return object;
    }
};

Talk about not seeing the forest for the trees...


Post a Comment for "Can't Include External Javascript In File"