Chrome throws the following error:
Uncaught TypeError: Property 'js' of object function
(){d.ready.apply(null,arguments)} is not a function
While Firefox throws a TypeError: head.js is not a function
Here is my code:
<!doctype html>
<html lang="eng" ng-app="app">
<head>
<meta charset="UTF-8">
<title>{{ page_title }}</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/headjs/0.99/head.core.min.js"></script>
</head>
<script>
head.js({ angularJS: "https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"},
{ jQuery: "http://code.jquery.com/jquery-1.10.1.min.js" },
{ internalApp: "app/js/app.js"});
head.ready('jQuery', function() {
$(document).ready(function() {
console.log('jQuery loaded successfully');
});
});
</script>
<body>
<!-- add data here -->
</body>
</html>
You have loaded the Responsive Design + Feature Detections script http://cdnjs.cloudflare.com/ajax/libs/headjs/1.0.3/head.core.min.js and not the Asset Loader http://cdnjs.cloudflare.com/ajax/libs/headjs/1.0.3/head.load.min.js
I just made the same mistake and found this post while looking up the answer :)
Related
I am trying to run a kmm project js files on a browser. Here the html:
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="../packages_imported/kotlin/1.5.10/kotlin.js"></script>
<script src="../packages_imported/KotlinBigInteger-bignum-js-legacy/0.3.2/KotlinBigInteger-bignum-js-legacy.js"></script>
<script src="../packages_imported/kotlinx-coroutines-core/1.5.0-native-mt/kotlinx-coroutines-core.js"></script>
<script src="../packages_imported/ktor-ktor-io-js-legacy/1.6.0/ktor-ktor-io-js-legacy.js"></script>
<script src="../packages_imported/kotlinx-serialization-kotlinx-serialization-core-js-legacy/1.2.1/kotlinx-serialization-kotlinx-serialization-core-js-legacy.js"></script>
<script src="../packages_imported/kotlinx-serialization-kotlinx-serialization-json-js-legacy/1.2.1/kotlinx-serialization-kotlinx-serialization-json-js-legacy.js"></script>
<script src="../packages_imported/ktor-ktor-utils-js-legacy/1.6.0/ktor-ktor-utils-js-legacy.js"></script>
<script src="../packages_imported/ktor-ktor-http-js-legacy/1.6.0/ktor-ktor-http-js-legacy.js"></script>
<script src="../packages_imported/ktor-ktor-http-cio-js-legacy/1.6.0/ktor-ktor-http-cio-js-legacy.js"></script>
<script src="../packages_imported/ktor-ktor-client-core-js-legacy/1.6.0/ktor-ktor-client-core-js-legacy.js"></script>
<script src="./parippu-vada/kotlin/parippu-vada.js"></script>
<title>Title</title>
</head>
<body>
</body>
</html>
This throws the following error:
_Collections.kt:1618 Uncaught TypeError: Cannot read properties of undefined (reading 'iterator')
at _Collections.kt:1618
at parippu-vada.js:23
at parippu-vada.js:25
Its shows error in collections.kt #:
/**
* Applies the given [transform] function to each element of the original collection
* and appends the results to the given [destination].
*/
public inline fun <T, R, C : MutableCollection<in R>> Iterable<T>.mapTo(destination: C, transform: (T) -> R): C {
for (item in this) <- this throw error
destination.add(transform(item))
return destination
}
Its probably related to kotlin version because the error is in auto-generated file. Is there anything I can do about this.
Am almost giving up on kmm, some inspiration would be nice !
I recently started working on this project last few days from CodingTrain, however I kept running into this 'split' error. I've tried looking around how to fix it but I'm very new to JS. If anyone can help I would greatly appreciate it.
Sketch.js
let brain;
function setup() {
createCanvas(640, 480);
let options = {
inputs: 34,
outputs: 4,
task: 'classification',
debug: true
}
brain = ml5.neuralNetwork(options);
brain.loadData('ymca.json', dataReady);
}
function dataReady() {
brain.normalizeData();
brain.train({epochs: 50}, finished);
}
function finished() {
console.log('model trained');
brain.save();
}
index.html
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.10.2/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.10.2/addons/p5.sound.min.js"></script>
<script src="https://unpkg.com/ml5#0.5.0/dist/ml5.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8" />
</head>
<body>
<script src="sketch.js"></script>
</body>
</html>
Split is reserved for strings so at some point looks like P5 is expecting a string but not getting it. You should be able to follow the error stack in your dev tools console and see what line of your code the error is coming from.
I am trying to use jQuery.Lighbox library but it fails to find the lightBox method.
What I did:
include jquery.lightbox.js (immediatly after jquery itself):
<html lang="en">
<head>
<meta charset="utf-8" />
<link href="/Content/site.css" rel="stylesheet"/>
<link href="/Content/jquery.lightbox.css" rel="stylesheet"/>
<script src="/Scripts/modernizr-2.5.3.js"></script>
<script src="/Scripts/jquery-1.7.1.js"></script>
<script src="/Scripts/jquery.lightbox.js"></script>
...
<head>
and within the body I am am wiring up the lightbox code to html elements:
<body>
<script type="text/javascript">
$(function () {
try
{
$('#gallery a').lightBox(); // Select all links with lightbox class
}
catch (err) {
var txt = "";
txt = "There was an error on this page.\n\n";
txt += "Error description: " + err.message + "\n\n";
txt += "Click OK to continue.\n\n";
alert(txt);
}
});
</script>
and quite expectantly the js code throws an error:
There was an error on this page.Error description: Object [object
Object] has no method 'lightBox'Click OK to continue.
I am new to jQuery, so if you can give me a hint what did I do wrong and how to fix it.
Thank you.
edit:
resolved : it turned out jquery.js has been include twice, and it was hiding jquery.lightbox function.
Object [object Object] has no method 'lightBox'
this mean lightBox method is not found which means lightbox js is not loaded properly..check it out...view the source..and make sure your path is correct
I have two scripts and I need to use script1 function in script2. Whats the best way to do it and Is there any simplification using prototype to access function in more scripts. I am using jquery.
script1
$(function(){
function process(){
// some code
}
})
script2
$(function(){
// I would like to use the process function here
}
Sample.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script type="text/javascript" charset="utf-8" src="Script1.js" ></script>
<script type="text/javascript" charset="utf-8" src="Script2.js" ></script>
<script>
</script>
<BODY onload='calling();'>
</BODY>
</HTML>
Scrip1.jc
function call(){
alert("Hi i am called from script2");
}
Scrip2.js
function calling(){
call();
}
Hope this help you.
You can use javascript functions as variables. So just reread your question about the same stuff about variables - Unable to access variable
So just do so your function will be available from global scope.
Just move the function declaration outside the ready event handler, that will make it globally available.
Another idea: use objects:
var Ob = {
process: function(callback) {
callback();
}
}
script1
$(function(){
Ob.process(function(){
... // code
});
});
script 2 (do same)
$(function(){
Ob.process(function(){
... //another code
});
});
If you are using same process function (means same body content, make same thing in both script) then
var Ob = {
process: function() {
...//put code
}
}
script1
$(function(){
Ob.process();
});
script 2 (do same)
$(function(){
Ob.process();
});
I try to use some 'dijit' widget from script, for example to change content or to connect event.
For this purpose I try to use 'data-dojo-id' attribute in html, which (as I understood) creates global object of type 'data-dojo-type' and name 'data-dojo-id'.
But I got errors... What I do wrong?
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Dojo test</title>
</head>
<body>
<div id="myDivId"
data-dojo-type="dijit.layout.ContentPane"
data-dojo-id="myDojoId">
Hello Everyone!
</div>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js" data-dojo-config="async: true, parseOnLoad:true"></script>
<script type="text/javascript">
require(["dijit/dijit", "dijit/layout/ContentPane"], function(){
//myDojoId.setContent("Hello World!"); // error : myDojoId is not defined
// Even this not working:
console.log(dijit.byId("myDivId")); // undefined
console.log(dijit.byId("myDojoId")); // undefined
});
</script>
</body>
</html>
data-dojo-id and jsId (deprecated) attributes create a global object referring to that dijit.
I believe you need to wrap the lookups in a ready() call
<script type="text/javascript">
require(["dojo/ready","dijit/dijit", "dijit/layout/ContentPane"], function(ready,dijit,ContentPane){
//shouldn't be defined yet
console.log(dijit.byId("myDivId")); // undefined
console.log(myDojoId); // undefined
ready(function(){
console.log(dijit.byId("myDivId"));
//note how data-dojo-id doesn't have the lookup
console.log(myDojoId);
});
});
</script>