Major issue with running d3.v3.js - javascript

I have made a html file based on: http://jsfiddle.net/kaliatech/4TMMD/
at the begning of my file, I have added:
<script src="data/d3.v3.js"></script>
<script src="data/nv.d3.min.js"></script>
<script src="data/nv.d3.js"></script>
<script src="data/tooltip.js"></script>
but I see this error: Error:
Invalid value for <circle> attribute cx="NaN" d3.v3.js:663
attrFunction.
Uncaught TypeError: Cannot read property '0' of undefined d3.v3.js:4157
So the tooltip cannot be shown. How is it possible that d3.v3.js has this error! Why do I recieve this error?

I believe you need to add a charset attribute so that the utf-8 characters in d3.v3.js are decoded correctly by your browser. This is the script tag recommended at http://d3js.org:
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>

Related

Why there exist error Uncaught ReferenceError: $ is not defined if add async?

My index like this :
...
<html >
<head>
...
<script src="/scripts/myapp.min.js"></script>
<script src="/scripts/myapp-themming.min.js"></script>
</head>
<body class="header-static">
<div class="page-container">
<!-- this is call header, navigaton, content, footer -->
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="/Content/assets/script/jquery-ui.min.js"></script>
...
<script type="text/javascript">
...
</script>
<script>
$(document).ready(function () {
...
});
</script>
</body>
</html>
If I test pages speed using gtmetrix. And gtmetrix recommendation for Defer parsing of JavaScript. So I try to add async like this :
<script src="/scripts/myapp.min.js" async></script>
<script src="/scripts/myapp-themming.min.js" async></script>
it showing following error,
Uncaught ReferenceError: $ is not defined
If I using defer, it make 3 error like this : Uncaught ReferenceError: $ is not defined, Uncaught TypeError: $(...).material_select is not a function, and Uncaught TypeError: $(...).select2 is not a function
How can I solve this error?
First move the two scripts in the <body> into the <head> section at the top (above the 3 dots you have added). This is what #Nijin Koderi meant.
The important thing is making sure that jQuery is ABOVE everything else so it is loaded first.
Secondly - you can't just use async as mentioned in the other answer I gave as you will end up with a race condition.
The reason you get less errors with async is purely down to load speed of resources, you will find that with enough loads you will get different errors depending on which scripts download the fastest.
It is much easier while you are learning this to use defer (in fact I nearly always use defer unless you are loading megabytes of JS or your site needs JS within milliseconds to work)
To quote the answer I gave
The easiest way [to defer parsing of JavaScript] is to add defer
attribute to each JavaScript request.
For better performance (difficult) I would recommend using async
instead as this will start downloading sooner and activate each Script
as soon as it is available.
However this often causes issues with 'race conditions' where scripts
may load out of order (i.e. if you are using jQuery and another script
loads before it that needs jQuery you will get an error).
Try defer first and if performance is good use that.
You have two errors as mentioned above, Uncaught ReferenceError: $ is not defined, Uncaught TypeError: $(...).material_select is not a function, and Uncaught TypeError: $(...).select2 is not a function
the first problem can be resolved by adding the following js file on the top before any other js as shown below
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">
...
<script src="/scripts/myapp.min.js"></script>
<script src="/scripts/myapp-themming.min.js"></script>
Next Error is for select2. For resolving this issue,add the following stylesheet and js file after jquery.min.js
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/js/select2.min.js">

Unexpected token < exception when I set charset="utf-8" in js file

I have book.jsp and book.js file. I was trying to set charset in js file like below.
<script src="/js/view/page1/main/book/book.js" type="text/javascript" charset="utf-8"/>
Jsp content loading without issue but getting below exception in the console while trying to load js file for that page.
Uncaught SyntaxError: Unexpected token <
You need to make sure to close the tag.
<script src="/js/view/page1/main/book/book.js" type="text/javascript" charset="utf-8"></script>

reactjs can't read https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.js:37752:65

I am trying to follow this tutorial so I copied the following code (from below the sub heading "Step 2: Adding JSX into the mix") directly into a file called index.html which I opened in chrome:
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.6/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.6/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.js"></script>
</head>
<body>
<div id="app"></div>
<script type="text/babel">
// Code omitted to keep sample short
</script>
</body>
</html>
But I got this error in the chrome console:
Uncaught DOMException: Failed to read the 'sessionStorage' property from 'Window': Access is denied for this document.
at https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.js:37752:65
at Object.423../isArguments (https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.js:37761:2)
at s (https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.js:2:619)
at https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.js:2:670
at Object.421.foreach (https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.js:37637:12)
at s (https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.js:2:619)
at https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.js:2:670
at Object.420../implementation (https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.js:37618:14)
at s (https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.js:2:619)
at https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.js:2:670
I'm not sure what to make of this error or how to fix it. Please note that I have not made any changes to the code, I copied it exactly as it was presented on the tutorial. Thanks for the help.
Seems like your browser is blocking access for external scripts to the sessionStorage.
Try following these steps: https://www.chromium.org/for-testers/bug-reporting-guidelines/uncaught-securityerror-failed-to-read-the-localstorage-property-from-window-access-is-denied-for-this-document

Sliding in Panel - JQuery Conflict

I am trying to add into my website (Magento Store) a slide in panel (https://codyhouse.co/gem/css-slide-in-panel/) and I am getting issues when including the JQuery.js file. It complains about not finding a particular function for other extensions. The result I could only find is that it is a common issue called JS conflict. I am newbie and any help will be appreciated.
List of errors:
prototype.js:5653 Uncaught TypeError: element.attachEvent is not a function
extendedreviews.js:14 Uncaught TypeError: $j(...).hoverIntent is not a function
prototype.js:5653 Uncaught TypeError: element.attachEvent is not a function
somesome.com/:777 Uncaught TypeError: $j(...).foundation is not a function
prototype.js:5734 Uncaught TypeError: element.dispatchEvent is not a function
I am including the JS for this panel in head file as
<script type="text/javascript" src="js/slidein/modernizr.js"></script>
<script type="text/javascript" src="js/slidein/jquery-2.1.1.js"></script>
<script type="text/javascript" src="js/slidein/main.js"></script>
Note that, before these 3 includes, there are many other JS included for third party extensions. The errors are related to files for these third party extensions
Try to add these Cdn's.I hope these will work fine.
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

Riot custom tag not loading (hello world example)

I have the most basic possible custom tag, but it's not mounting. Also if I use riot.mount('*') I get this error in riot.min.js
Uncaught SyntaxError:
Failed to execute 'querySelectorAll' on 'Document': The provided selector is empty.
Compiled Tag
riot.tag('test', '<div>Hello world!</div>', function(opts) {
});
Index file:
<!doctype html>
<html>
<head></head>
<body>
<test></test>
<script src="https://cdn.jsdelivr.net/riot/2.2/riot.min.js"></script>
<script src="tags/test.js" type="riot/tag"></script>
<script>riot.mount('test')</script>
<!-- <script>riot.mount('*')</script> throws error -->
</body>
</html>
Oh was mixing the pre-compiled and browser compiled syntax. After removing type="riot/tag" from my tag reference it mounted correctly.

Categories