I have an HTML file :
<!DOCTYPE HTML>
<html lang="en-US" ng-app="Todo">
<head>
<meta charset="UTF-8">
<title>DemoAPI</title>
<meta name="viewport">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<link rel="stylesheet" href="./Client/css/styling.css" />
<script type="text/javascript" src="core.js"></script>
</head>
The error says:
Uncaught SyntaxError: Unexpected token < core.js: 1
It shows the error at <!doctype html> of the app.html.
core.js looks like this:
angular.module('Todo', [])
.controller('mainController', function($scope, $http)
{
$scope.formData = {};
// get all and show them
$http.get('/musicians')
.success(function(data) {
$scope.todos = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
//get with an id
$scope.getOneTodo = function() {
$http.get('/musicians' + id)
.success(function(data) {
$scope.todos = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
};
// send the text to the node API
$scope.createTodo = function() {
$http.post('/musicians', $scope.formData)
.success(function(data) {
$scope.formData = {}; // clear the form
$scope.todos = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
})
};
// delete
$scope.deleteTodo = function(id) {
$http.delete('/musicians' + id)
.success(function(data) {
$scope.todos = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
};
/*
$scope.updateTodo = function(id) {
$http.delete('/musicians' + id)
.success(function(data) {
$scope.todos = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
};*/
});
It also gives me Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.14/$injector/modulerr?p0=Todo&p1=Error%3A%2…gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A17%3A381)
Besides, in console, when I click at core.js, it shows the contents of app.html and name it core.js.
Here is the snapshot:
Also, as in the image, when I click index.html, it shows app.html. However, I do not have any file that is named index.html and I load app.html by default instead of index.html.
I have tried adding/removing type="text/javascript" but no help with that either.
Also, status 200 is returned on get request for core.js.
What might be wrong?
Your page references a Javascript file at /Client/public/core.js.
This file probably can't be found, producing either the website's frontpage or an HTML error page instead. This is a pretty common issue for eg. websites running on an Apache server where paths are redirected by default to index.php.
If that's the case, make sure you replace /Client/public/core.js in your script tag <script type="text/javascript" src="/Client/public/core.js"></script> with the correct file path or put the missing file core.js at location /Client/public/ to fix your error!
If you do already find a file named core.js at /Client/public/ and the browser still produces a HTML page instead, check the permissions for folder and file. Either of these might be lacking the proper permissions.
In my case I got this error because of a line
<script src="#"></script>
Chrome tried to interpret the current HTML file then as javascript.
I experienced this error with my WordPress site but I saw that there were two indexes showing in my developer tools sources.
Chrome Developer Tool Error
So I had the thought that if there are two indexes starting at the first line of code then there's a replication and they're conflicting with each other. So I thought that then perhaps it's my HTML minification from my caching plugin tool.
So I turned off the HTML minify setting and deleted my cache. And poof! It worked!
Check your encoding, i got something similar once because of the BOM.
Make sure the core.js file is encoded in utf-8 without BOM
Well... I flipped the internet upside down three times but did not find anything that might help me because it was a Drupal project rather than other scenarios people described.
My problem was that someone in the project added a js which his address was: <script src="http://base_url/?p4sxbt"></script> and it was attached in this way:
drupal_add_js('',
array('scope' => 'footer', 'weight' => 5)
);
Hope this will help someone in the future.
We had the same problem sometime ago where a site suddenly began giving this error. The reason was that a js include was temporarily remarked with a # (i.e. src="#./js...").
I had this problem in an ASP.NET application, specifically a Web Forms.
I was forcing a redirect in Global.asax, but I forgot to check if the request was for resources like css, javascript, etc. I just had to add the following checks:
VB.NET
If Not Response.IsRequestBeingRedirected _
And Not Request.Url.AbsoluteUri.Contains(".WebResource") _
And Not Request.Url.AbsoluteUri.Contains(".css") _
And Not Request.Url.AbsoluteUri.Contains(".js") _
And Not Request.Url.AbsoluteUri.Contains("images/") _
And Not Request.Url.AbsoluteUri.Contains("favicon") Then
Response.Redirect("~/change-password.aspx")
End If
I was forcing logged users which hadn't change their passwords for a long time, to be redirected to the change-password.aspx page. I believe there is a better way to check this, but for now, this worked. Should I find a better solution, I edit my answer.
For me this was a case that the Script path wouldn't load - I had incorrectly linked it. Check your script files - even if no path error is reported - actually load.
I had the same issue. I published the angular/core application on iis.
To change the Identity of the application pool solved my issue. Now the Identity is LocalSystem
I also faced same issue.
In my case when I changed script attribute src to correct path error got fixed.
<script src="correct path"> </script>
I got my problem fix by removing slash / at the and of link tag.
<link rel="manifest" type="application/manifest+json" href="https://kal.my.id/manifest.webmanifest" title="YakaLee">
i seen your's
<link rel="stylesheet" href="./Client/css/styling.css" />
try remove the slash like so:
<link rel="stylesheet" href="./Client/css/styling.css">
I was facing the same issue recently. The js path which I provided inside my HTML file was correct. Still, during the time of calling the js file, it was prompting me an uncaught exception in the console. Furthermore, my app is running fine on localhost but facing the issue on prod.
As the paths to js files are already correct, I just give it a try to change my calling .js file to another directly and change the root path and that worked.
Try changing the path of your .js file to another directory.
If someone around still have this issue as I had. Try adding this line of code to your header.
<base href="/" />
It will align your html file to the static directory on Nodejs you are setting.
I am getting this err
Uncaught ReferenceError: $ is not defined.
I have searched and found that the usual cause of this is not having jQuery declared in the right place but I think I have it right.
Thanks in advance.
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="ajax2.js"></script>
<script type="text/javascript">
var slideimages = new Array() // create new array to preload images
slideimages[0] = new Image() // create new instance of image object
slideimages[0].src = "images/aib.jpg" // set image src property to image path, preloading image in the process
slideimages[1] = new Image()
slideimages[1].src = "images/paddypower.jpg"
slideimages[2] = new Image()
slideimages[2].src = "images/rtegaa.jpg"
slideimages[3] = new Image()
slideimages[3].src = "images/ssgaa.jpg"
$(document).ready(function(){
function get_weather()
{
var p = $("#code").val();
var u = ($('#u').attr('checked')) ? '&u=c' : '';
var to_load = 'get_weather.php?p='+ p + u;
$("#weather").html('<img style="margin-top: 104px;" src="ajax-loader.gif" align="absmiddle">');
$("#weather").load(to_load);
}
$(window).load(get_weather); // Trigger "get_weather" when the window loads
// Trigger "get_weather" when the form objects are used
$("#code").change(get_weather);
$("#u").click(get_weather);
});
The solution:
1) Use Google CDN to load jQuery
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
2) It is compatible with jQuery v1.5-v1.7 because most of the methods were deprecated in jQuery 1.8+. This is the reason I've used v1.5 of Google CDN jquery in point 1. Most of the examples on cycle plugin use jquery 1.5.
3) Clear Your browser cache, It is the main culprit most of the times.
4) PLease check the loading of jquery using the code below
if(typeof jQuery!=='undefined'){
console.log('jQuery Loaded');
}
else{
console.log('not loaded yet');
}
Probably you called jQuery.noConflict() somewhere.
To solve this, wrap your code like this:
(function($, undefined){
if( !$ )
{
console.log('jQuery failed to load');
return;
}
//jquery code here
})(window.jQuery);
This will prevent the jQuery.noConflict() from affecting your code and you can debug in case jQuery is having some troubles.
Also, watch your 'Network' tab, on the Element Inspector (press F12).
This error will not occur if the file "jquery-1.2.6.min.js" is not present in the location mentioned in your script tag. From your code, the jquery file should be present in the same folder as your startup page.
I'll check the following things when this error occurs
1) Make sure the jquery script file is present in the correct location
2) Name of the jquery file is same as referenced in script tag
3) In browsers console window, there is a debugger or source tab which shows all the script and CSS files used by the page. Check jquery is present under the sources tab of the browser
I am developing the mobile application using Oracle MAF. In that application I need to implement the Signature capture functionality.
For that I have downloaded the Signature Capture Demo app from this link.
And trying to integrate with my application. I did all the necessary settings mentioned in that link.
But after running the application I am getting following error
TypeError: Object[object Object] has no method 'signature'
The Piece of code as follows
<![CDATA[
<script type="text/javascript">
(function()
{
makeSig = function() {
try
{
var sigElement = document.getElementById("sig");
if (sigElement == null)
alert("sigElement not found");
var sigJq = $(sigElement);
sigJq.signature();
sigJq.signature({guideline: true});
}
catch (problem)
{
alert("Problem with verbatim code: " + problem);
}
}
window.setTimeout(makeSig, 250);
})();
</script>
<div id="sig" style="height:200px;width:99%"></div>
]]>
Please let me know why it is not able to find the signature method. I have also included all the required .js files in the project.
Thanks in Advance.
Make sure you are properly including the library:
<script type="text/javascript" src="js/jquery.signature.js"></script>
then try something like this
var sigJq = $("sig");
sigJq.signature();
I am using Log4js Library to print the log message in a file. In that I am getting 2 issues. Such as:
12:00:40 PM ERROR Log4js - TypeError: netscape.security.PrivilegeManager is undefined
in Non-IE Browser. Please tell me how to fix this exception. While Using IE , It's
working fine.
How to get the CATALINA_HOME in the JavaScript part. I am using Tomcat.
To get this CATALINA_HOME in Log4j, we need to write as follow
log4j.appender.FILE.File=${catalina.base}/logs/MyLogs.log.
If I'll write the catalina.base, not working in the JavaScript.
Here is my code please have a look on my code and detect the error causing line to have the solution:
<script type="text/javascript">
function myFunction(name) {
var date = new Date();
var log = Log4js.getLogger("fileAppender");
log.setLevel(Log4js.Level.ALL);
var toAppend=date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
var fileAppender = new Log4js.FileAppender("${catalina.base}\\logs\\JSLogging."+toAppend+".log");
log.addAppender(fileAppender);
log.debug("My Debugging");
log.info("My Information");
}
</script>
try adding <script type="text/javascript" src="log4javascript.js"></script> in the code seems it is not able to get the reference of the main script.
see if this can help you
<script type="text/javascript">
// Create the logger
var log = log4javascript.getLogger();
// Create a PopUpAppender with default options
var popUpAppender = new log4javascript.PopUpAppender();
// Change the desired configuration options
popUpAppender.setFocusPopUp(true);
popUpAppender.setNewestMessageAtTop(true);
// Add the appender to the logger
log.addAppender(popUpAppender);
// Test the logger
log.debug("Hello world!");
</script>
enter code here
use this link
I thought that I was doing everything right, however I keep getting this error. $(document).ready(); // undefined in the console. I imported my jquery script.
<script src = "//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script >
$(document).ready(function(){
$("div#chat").hide();
});
function send_file(){
}
function remove_selected(){
}
function changeToFile(){
}
function chatToProfile(){
}
function changeToChat(){
}
</script>
If you're running this file locally (which I suspect you are...), this will attempt to find the referenced file on your local system, which will not be there.
To fix this, instead use this:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
Need to add http: in your script reference. try this:
<script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
i use like this :) and those who says HTTP required. read this article for relative Protocol URL Protocol relative url
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined') {
document.write(unescape("%3Cscript src='/js/jquery-1.8.3.min.js' type='text/javascript'%3E%3C/script%3E")); //Load the Local file (if google is down for some reason)
}
</script>
Script url that you are using for loading is perfect.
You can check your Url by posting "http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" in browser url if you will get the javascript text file then it is working.
I test it and that url is working fine on my side.Error is some where else either there is restriction(security resons) or there is internet connection problem on the system when ever you run that web application on the system.
solution is either use minified copy in you web application and provide the relative path or use
<script type="text/javascript">
if (typeof jQuery == 'undefined') {
document.write(unescape("%3Cscript src='/js/jquery-1.4.2.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
You always can check if jQuery is already loaded in the memory and the library is ready to use:
if (typeof jQuery !== 'undefined') {
//do whatever here
}