A very basic question
Cannot load external javascript resource on server
I am working on a Play framework project. I've made some basic html view with some Javascript. It works correctlly when I have my js code in the actual view.
However, when I tried moving js code to a separate file and load it using
<script> src="main.js" </script>
It works correctly when opened using plain chrome browser. However when I run it on server and it fails and chrome dev console prints the following message
GET http://localhost:9000/main.js 404 (Not Found)
I've tried setting up a GET request on targer URL but cannot pass main.js as an arguement to Ok method
def getmainJs()= Action {
Ok()
}
Is there a painless way to access the js code or do I have to go through the process of setting up the JavacriptRouter menntioned here. The app is only going to be 2 views to I kind of don't care about scalability
I created an example on how to serve a Javascript file:
Routes:
GET /foo sk.ygor.stackoverflow.q53319493.controller.ApplicationController.foo
GET /assets/*file controllers.Assets.versioned(file)
View:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script src="#routes.Assets.versioned("main.js")"></script>
</body>
</html>
Related
It seems when i use TEdgeBrowser and navigate to my html file, that loading external local javascript files in that html does not work. -nothing happens
for example i have in html:
<!DOCTYPE>
<html>
<head>
</head>
<body>
<script src="test.js"></script>
</body>
</html>
And javascript file:
alert('HELLO');
It is simple example that should message me HELLO, but doesn't matter what is in javascript, it just doesn't load.
I don't get any DevTools errors.
When i run the html in normal browser for example chrome or edge on my pc, it works fine.
Also, when i have a script that is not local, but remote, then it works too. So it seems that the problem is only with local files. (I run delphi as administrator).
What could be the problem? I have delphi 10.4.2
Trying to get phonegap to work on an iPhone.
With a completely blank project, except for jsconsole for debbuging and the cordova.ios.js file, I keep getting errors as soon as the app loads:
file:///var/mobile/Applications/19E49099-C481-44B4-8803-07A0390EA3B3/pplats.app/www/index.html:1link
TypeError: 'undefined' is not a function
I cant get anything more out of the stacktrace. Why could I be getting a TypeError? Completely running out of ideas here.
The HTML file:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="cordova.ios.js"></script>
<script src="http://jsconsole.com/remote.js?79F01FAA-19A6-40C2-B32F-7FEF1D5E3998"></script>
</head>
<body>
testing......
</body>
</html>
What does your project directory structure look like?
My guess is that this is related to the src="cordova.ios.js" link, have you tried specifying an absolute or root-relative (/path-to-file/cordova.ios.js) path to the js file?
i am using requires.js 2.0. I have the following simplified use case:
my HTML file:
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<script type="text/javascript" data-main="apptest.js" src="../_js/libs/require/require.js"></script>
</head>
<body>
</body>
</html>
And then in apptest.js:
requirejs.config({
paths: {
'text': '../_js/libs/require/text'
}
});
requirejs(
['text!boxes.html'],
function (Boxes) {
alert("done");
}
);
Ok, so it doesn't really do much, but enough to make my point. Only in Firefox (14.0.1) i get an exception "uncaught exception: java.security.AccessControlException: access denied (java.io.FilePermission .\boxes.html read)".
So, require.js successfully loaded the text plugin, but fails loading my html file, which i want to use as a template later on. In Google Chrome and even IE9 it works just fine. I am on Windows 7.
I am running this on a local webserver, so no file://... requests here.
I have checked, if i have any special permissions set on the html file, but have not found anything suspicious.
Anyone have an idea?
Update: Running the test in Firefox 13.0.1 does actually work for me without errors. So could it be, that this is a bug, that has been introduced in firefox 14?
I was having the same problem a minute ago. I've fixed it by doing the following in the main.js file (where you setup the config)
Before the
require.config({.....
add the following code:
Packages = undefined;
This should do the trick.
You should have something like this:
Packages = undefined;
require.config({
baseUrl: theAppBaseUrl,
paths: {
Basically the explanation is that it is trying to use Java to get the file instead of an ajax request (for whatever reason). This forces it to use an XHR object to fetch it.
Cheers!
I use Django for my applications, and for some strange reasons a new project am working on has started mis-behaving with the following error when I try to load the page on a browser.
Resource interpreted as Script but transferred with MIME type text/html: "http://127.0.0.1:8000/site_media/js/jquery-1.7.js"
my view looks like this;
#csrf_exepmt
def home(request):
render_to_response("myapp/home.html",{}, context_instance=RequestContext(request))
My HTML template:
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Home</title>
<script type="text/javascript" src="jquery-1.7.js"></script>
</head>
<body>
<h1>Welcome Home!</h1>
</body>
</html>
I have never seen anything like this in the past for any of my projects.
I am testing on Windows, Chrome 18.0. I have also tried on FF6 and Firebug is throwing some error on the first line of my html file.
All the suggestions from the net that I am trying are not working.
I have also tried to use the technique of supplying the MIME type manually via the django render shortcut but with no luck.
What am I missing? My other projects are working normally, even without the MIME settings.
Note: If I leave the "src" attribute of the script tag empty, the page loads well.
I resolved the issue! the problem was a bad malformed url conf pattern.
My first line in the url patterns was looking like this
url(r'$', 'myapp.views.home'),
instead of
url(r'^$', 'myapp.views.home'),
Notice i was missing the "^" before the "$" sign.
Thank you.
I'm having a bit of a problem getting my custom JavaScript file to play nice in Google chrome when jquery is being loaded in my Magento site. This problem only seems to be appearing in Google chrome. I've tested for the problem in both Linux Ubuntu 10.10 (chrome 10.0.648.114 beta) and Windows XP (chrome 9.0.597.98). FF, Safari, IE don't seem to have this problem.
When jQuery is added to the JS files to include, my personal JS file does not work when a hard refresh is sent (force a 200 request of the js file). if I do a regular refresh (304 request of the js file) and have it load from cache, then it works.
I have gone so far as to create a dummy page outside my magento site and I'm still getting this problem when I include the JS files from the magento site. but, if I move the JS files outside the magento site it works fine?
I have caching disabled in my magento admin and to my knowledge there isn't any module or custom code/plugins that would affect JS files that are to be included.
Here is an example of my dummy page that is sitting in the root directory of my server
The only thing gearlists.js has in it, is
alert('external');
so I would expect two alert popups when I load that page. but on hard refreshes, I'm only getting one popup. "Internal".
If i turn around and do a regular refresh, both JS files are loaded from the browser cache w/ a 304 status code and I get two popups "External" then "Internal"
Does Not Work With Hard Refresh
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://VIRTUAL_SERVER_FOR_MAGENTO_SITE/catalog/js/jquery/jquery-1.5.1.js"></script>
<script type="text/javascript" src="http://VIRTUAL_SERVER_FOR_MAGENTO_SITE/catalog/js/ads/gearlists.js"></script>
<script type="text/javascript">
alert('Internal');
</script>
</head>
<body>
</body>
</html>
Always Works
In this example, if I move the JS files out of the magento virtual server and into the root directory of my server, everything always works as expected. two popups are shown w/ every page refresh
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://localhost/jquery-1.5.1.js"></script>
<script type="text/javascript" src="http://localhost/gearlists.js"></script>
<script type="text/javascript">
alert('here');
</script>
</head>
<body>
</body>
</html>
Now if I remove the jquery file from my test, my custom js file always works fine whether its served from withing my magento VS or not...There is always two popups.
I'm a bit stuck on what could be causing this. Any ideas would be greatly appreciated.
OK, I figured this out. dumb mistake, but it took some time. The directory for the files were the initials for the site name js/ads/gearlists.js
turns out my adblock extension uses a regex to find the word "ads" and filtered my script out. when I adjusted the directory from ads to adsinc problem went away.
makes sense that id didn't work in linux or windows since my chrome extensions are synced.
Two tips:
You may want to install the mxperts jquery plugin extension on Magento Connect - it is free and helps debugging jquery scripts that people put on your Magento site.
Google Chrome has no known way of refreshing the cache - you can rename your js files though, then it loads new ones.