Does anybody know if the order of linked external JavaScript files ever matters?. I've never known so but with YUI it seems to be the case when linking library files.
I am making HTTP get Ajax requests, using YUI and I have this HTML file and these 4 files linked (last is my Ajax file and the first 3 are library files from the framework downloaded from the build folder)...
<html>
<head>
<title>Ajax get page with YUI........</title>
<script src="yahoo-min.js"></script>
<script src="event-min.js"></script>
<script src="connection-min.js"></script>
<script src="ajax.js"></script>
</head>
<body>
<h3>Mike's Wednesday Ajax get page........</h3>
<div id="info">
This text will be replaced by Ajax dynamically........
</div>
</body>
</html>
If I link the library files in any other order, the call fails and I get errors. I'm just wondering as new to Ajax and YUI and as I've said, I've never experienced this before.
Thanks in advance.
If you stick with YUI 2, I would advice you to use the dependency configurator there: http://developer.yahoo.com/yui/articles/hosting/
It will tell you what files to include and in what order.
Related
Situation:
I have a server side running with express.js and there I get data from SQL database. I would like to show this data to the client side, by sending it to the client.
In the front-end, I need to take this data and make it into a chart. It is possible to do it with the tag in the HTML and include the Plotly library, which I want to use. However, I would like this operation to be done in a separate file, an external JS script for client. This avoids hard-to-read code in the HTML.
The problem is, how can I import Plotly to the external front-end file and use it?
I hope I understood your need correctly :
One simple option would be to include both of your script in your html related document with the one required by the second one first :
...
<script src="path script 1" />
<script src="path script 2 depending on script 1" />
so in your case using CDN :
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="path of your script where you use ploty"></script>
PS:
Also just a proposition but did you thing about importing Ploty in your js backend and use it in your front-end ? or with post/get or with socket ?
Well, simply load it from a CDN :) That's what CDNs are here for
<script src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/1.33.1/plotly-basic.min.js">
I found this example on w3schools.com and it should be working(it works on the website) but it doesn't work when I write it on my IDE(Atom).the home page is looking good but when I clicking the button nothing happened and it's not loading the demo_test.txt file. what am I doing wrong? or maybe something is missing?
home.html
$(document).ready(function(){
$("button").click(function(){
$("#div1").load("demo_test.txt");
});
});
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
<button>Get External Content</button>
</body>
</html>
demo_test.txt
jQuery and AJAX is FUN!!!
This is some text in a paragraph.
To start use Ajax, you must host your website or application on your machine, this called localhost.
There is many FREE applications you can use to create a localhost:
https://www.appserv.org/en/ .
https://www.apachefriends.org/index.html .
IIS *.
Download any of applications above and install it, it's very easy.
After installation, you can access your website with link http://localhost or http://127.0.0.1 .
You can create localhost without using any applications with IIS (Internet Information Services), but it's complicated compared to above applications.
I need your help with a strange problem.
The company I work for has a company website.
I have been updating pages on their website the last couple of days.
After updating, I decided to upload the website,
but suddenly the javascript doesn't work anymore.
I get the following error when I press f12
Uncaught SyntaxError: Invalid or unexpected token
base.js:1 Uncaught ReferenceError: $ is not defined
at base.js:1
On the test server (my own server) it works without any problems.
On the main server (company server) it doesn't work.
What could be the issue for this?
It's not on just one page, it's on every single page that the Javascript doesn't work.
[update]
I know about the different versions of Javascript.
This is already fixed in the testing environment of the company website.
This still doesn't fix the current problem.
Thank you
Wesley
On the test site you use jQuery 3.3.1:
<script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>
On the main site you use jQuery 1.10.1:
<script src="https://www.aska-ltd.jp/js/jquery-1.10.1.min.js"></script>
Please both use v3 if you don't have specific needs.
It looks like you are using jQuery for your JavaScript code.
The header of the first page contains a tag for loading jQuery:
<script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>
But on the second page, you never load jQuery.
As I don't know how the file structure of your server is, I cannot tell you the exact path, but you need to make sure you load jQuery in a similar way on your company website.
EDIT:
I noticed that you load jQuery from https://www.aska-ltd.jp/js/jquery-1.10.1.min.js. However, this file is not the original file (compared to https://code.jquery.com/jquery-1.10.1.min.js using MD5). If you want to use this old version (not recommended), you can try to re-download it or simply load jQuery in its latest version from its official server (recommended).
As #NoobTW and #SapuSeven have said, there is an error in the jQuery script on the production site.
On the production site, try replacing this <script src="https://www.aska-ltd.jp/js/jquery-1.10.1.min.js"></script>
with this <script language="JavaScript" type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
Also, if you load jQuery from a CDN, it may help simplify things. Here is one option for jQuery 3: <script
src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha256-3edrmyuQ0w65f8gfBsqowzjJe2iM6n0nKciPUp8y+7E="
crossorigin="anonymous"></script>
See here for more options: https://code.jquery.com/
JQuery never loads at all on the main server. I tried taking the code from the file on the server and evaluating it, but discovered some sort of corruption in the JQuery file your server is returning:
If the same thing happens with an updated version of JQuery, check whether it’s also corrupted. It may be some sort of transformation the server is incorrectly performing.
Is there any different between include external js file and write down javascript in the html page.
Case 1
test.html
<html>
<head>
<script type="text/javascript" src="test.js"></script>
</head>
<body>
</body>
</html>
test.js
alert('aaa');
Case 2
test.html
<html>
<head>
<script>
alert('aaa');
</script>
</head>
<body>
</body>
</html>
Case 1 execute more faster than Case2 if my memory services me right. But I am not sure. Moreover, I cannot find the relative documents or articles to support my ideal. May someone help me?
Case 1 is is slightly slower at first, because it needs to do a second request to get the script, so there is a little overhead.
However, the browser will cache the javascript file, so if you have multiple pages that share the same script, Case 2 will be more efficient, because for subsequent pages, the browser already has the cached script and doesn't need to download it again.
Also, most browsers will allow opening two connections to the same server, so it may download the page and the script simultaneously on the first request, although it depends on size of the page and the script, the server, the client and the internet properties (latency and speed) which solution is faster.
Case 1: will retreive the script from the server and run it syncrhonously (script file will be cached on subsequent requests, file can be minified)
Case 2: will have the script loaded as part of the page (no extra page request), and run when script tag is loaded into dom.
both: will hold up page at that point
Info: http://webdesign.about.com/od/speed/a/script-placement-for-speed.htm
I'm tring to understand how to connected my html with another file js, but the issues is with this software call topsytle4 it a trail basic,but for some reason it show the file but no feature can be us that could be use.
Add this line between <head> and </head>:
<script src="your_js_path_here"></script>