Bootstrap Installation Issues - javascript

I've been trying to install Bootstrap into a project that I'm working on, but I'm being hit with Uncaught Error: Bootstrap's JavaScript requires jQuery. I've installed both through Bower, so I'm not sure whether that's related, but it's not having issues finding the files, so I don't think it is. Upon Googling the issue, I realized that the order in which I reference the script files matters, so I changed it to reflect what I had read, but that didn't fix the issue. When I looked into the directories in the file explorer, I saw a file called core.js, but including that didn't help either. I fairly certain that it's something to do with the way I reference files, so I'll provide that code, but feel free to ask if anything more is required.
index.html (root folder, following text is in body):
<script src="./bower_components/jquery/dist/jquery.js"></script>
<script src="./bower_components/angular/angular.js"></script>
<script src="./bower_components/angular-route/angular-route.js"></script>
<script src="./bower_components/angular-animate/angular-animate.js"></script>
<script src="./bower_components/angular-aria/angular-aria.js"></script>
<script src="./bower_components/angular-material/angular-material.js"></script>
<script src="angulator.js"></script>
<script src="./components/calculator/calculator.controller.js"></script>
<script src="./bower_components/bootstrap/dist/js/bootstrap.js"></script>

I think you might have confused jQuery with angular. You are not including jQuery, but you are including angular (including angular-material, which is a competing framework to bootstrap).
If you want to use bootstrap with angular, you probably want to use ng-bootstrap instead of the standard Bootstrap JS, since it allows you to interact with Bootstrap components from inside your angular components. If you do this via the "standard" (non ng-bootstrap) JavaScript, things will start falling apart as soon as the Bootstrap JS mutates the DOM. You would also be unable to infer the view state from your component state (since you would need to call the functions of the bootstrap JS instead of data binding), which is pretty much the whole idea of angular.

You need jquery to remove the error
bower install jquery

I don't see you referencing jQuery in the code you provided. You've installed it via Bower, but you will still need to add a reference to it.
<script src="./bower_components/jquery/jquery.js"></script>
<script src="./bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="./bower_components/angular/angular.js"></script>
<script src="./bower_components/angular-route/angular-route.js"></script>
<script src="./bower_components/angular-animate/angular-animate.js"></script>
<script src="./bower_components/angular-aria/angular-aria.js"></script>
<script src="./bower_components/angular-material/angular-material.js"></script>
<script src="angulator.js"></script>
<script src="./components/calculator/calculator.controller.js"></script>

Import jQuery script before, like this:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="./bower_components/angular/angular.js"></script>
<script src="./bower_components/angular-route/angular-route.js"></script>
<script src="./bower_components/angular-animate/angular-animate.js"></script>
<script src="./bower_components/angular-aria/angular-aria.js"></script>
...

Bootstrap needs jQuery to work properly
Here is how you should include them both
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap</title>
<link rel="stylesheet" href="css/bootstrap.min.css"> <!--Bootstrap CSS-->
<link rel="stylesheet" href="css/main.css"> <!--Your custom css file-->
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Your content goes here -->
<script src="js/jquery-1.12.4.min.js"></script><!--jQuery -->
<script src="js/bootstrap.min.js"></script><!--Bootstrap js-->
<script src="js/main.js"></script> <!--Your custom javascript file-->
</body>
</html>

I think you have made a mistake while referencing JQuery.
It should be like :
<script src="bower_components/jquery/dist/jquery.min.js"></script>
and also make sure that you have included it before any other script file.
The correct way to include JQuery is also given on bower.io under Use Packages https://bower.io/

Related

SignalR proper script placement

ok so I decided to post another question (separate from my other one/edited it. this one is more on ordering of scripts).
So my problem is this: I have this at the header
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>
then at the bottom I got:
<script src="assets/js/app.min.js"></script>
<script src="assets/js/scripts.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<!--Reference the jQuery library. -->
<script src="Scripts/jquery-1.10.2.min.js" ></script>
<!--Reference the SignalR library. -->
<script src="Scripts/jquery.signalR-2.1.2.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="signalr/hubs"></script>
<!--Add script to update the page and send messages.-->
</form>
Problem is I don't know where to correctly place the scripts/proper ordering placing signalR at the very bottom removes my Navbar/animations/transitions which is in scripts.js,
placing the signalR above it will fix the Navbar issue but the signalR will stop working.
First thing I see is that you have 2 different versions of jQuery loaded.
At the top -
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
At the bottom -
<script src="Scripts/jquery-1.10.2.min.js" ></script>
You should only have 1 version. This is probably causing most of your issues. You may have some other conflicts running both bootstrap and jquery-ui (not validated) if similar js/css is applied between both. You may want to search for conflicts and see what impacts you.
As far as order goes load:
jQuery-x.x.x.min.js
bootstrap.min.js
jquery-ui.js
signalR-2.1.2.min.js
signalr/hubs

One part of my web app shows only sometimes

I am developing my first web app for learning purposes. It consists on a calendar wher you can add tasks, edit, and remove them asynchronously. Simple.
Everything seemed to work fine but once I uploaded it to my hosting, one friend reported me he can´t see the calendar, only the header and the footer... he says it happens on all browsers, but that on the smartphone it works fine... I checked myself and I can see it fine on all my browsers (that´s why I have not noticed), but happens the same bug on smartphone! It is just the same problem my friend had, but on the opposite device.
I contacted the hosting, and changed the PHP version to the most similar I had on the XAMPP I used to develop it... (5.6.32 on xampp and 5.6.35 on the hosting), but the problem still goes on.
I also tried to update bootstrap version. Calendar is done with bootstrap, JS (with some ES6 features like importing-exporting modules) and jquery returning data through PHP from a database... nothing special.
Do you know what could be happening? To see the calendar you must be logged.
If you want to log and see it, use these fake credentials:
email: test#gmail.com
pass: 12345678
and this is the link
http://myreminder.avanzartewebs.com/
I will put the head tag of the problematic file to see if it can give you a hint
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" defer></script>
<!-- Latest compiled and minified CSS -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous" defer></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.bundle.min.js" integrity="sha384-lZmvU/TzxoIQIOD9yQDEpvxp6wEU32Fy0ckUgOH4EIlMOCdR823rg4+3gWRwnX1M" crossorigin="anonymous" defer></script>
<link rel="stylesheet" type="text/css" href="../assets/css/styles.css">
<script src="getAndPrintDate.js" defer></script>
<!--<script src="assets/js/crearCalendario.js" defer></script>-->
<script src="view_crearAnioCompleto.js" type="module"></script>
<!--<script src="assets/js/buildList.js" defer></script>-->
<!--the scripts with type=module (which work with modules using the imports) are defer by default-->
<script src="../controls/clickOnCell.js" type ="module" ></script>
<script src="../controls/taskSubmit.js" type ="module" ></script>
<script src="../controls/listButtonsClick.js" defer ></script>
<script src="../controls/editTaskSubmit.js" type="module" ></script>
<script src="../assets/js/fontawesome-all.js" defer ></script>
</head>
Try downloading those instead of having them linked from their site and try that. My the host is blocking it. Thats something i would try just to see.
<!-- Latest compiled and minified CSS -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous" defer></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.bundle.min.js" integrity="sha384-lZmvU/TzxoIQIOD9yQDEpvxp6wEU32Fy0ckUgOH4EIlMOCdR823rg4+3gWRwnX1M" crossorigin="anonymous" defer></script>

Javascript files not loading in sources

So I have a landing page up at http://mytestosteronekit.com. Im using Leadpages to create the page. I have an index.html file that pulls in the leadpage with script in the head. I am also including bootstrap CSS, a custom stylesheet for style overrides, bootstrap JS, and a custom JS file. The css links are loading just fine and work on the page. Mainly have this for the navbar. But the js files are not firing and I can't figure out why.
I have them included right before the closing body tag. They show while inspecting, but they don't load in the sources. I was using relative url paths originally but switched to an absolute path just for security. Still no go.
I need this navbar to be working on mobile, please help me!
Bootstrap requires jQuery to be loaded before firing. All I needed to do to fix this problem was call to jQuery before calling the other scripts. Problem solved. No interference with Leadpages scripts.
Try put <script> tags lines before the closing tag </body>. I did it for you below:
<html>
<head>
<meta charset="UTF-8">
<!-- Bootstrap -->
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<!-- Custom CSS -->
<link rel="stylesheet" type="text/css" href="css/style.css">
<meta name="leadpages-meta-id" content="144ccecf3f72a2:1696aa1f6b46dc" /><meta name="leadpages-serving-domain" content="https://crawfordobrien.leadpages.co" /><meta name="leadpages-served-by" content="html" />
</head>
<body>
<script src="http://mytestosteronekit.com/js/bootstrap.min.js" type="text/javascript"></script>
<script src="http://mytestosteronekit.com/js/custom.js" type="text/javascript"></script>
<!-- Leadpage -->
<script type="text/javascript" src="https://my.leadpages.net/template/load-144cc5ec6639c5-1696a36f6639c5-dnoeNG8gtnHtHMXGoqpWmbNBhgtazHED.js"></script>
</body>
</html>

twitter Bootstrap Popovers (and bootstrap in general) not Working

I realize this question has been asked multiple times before, but unfortunately, I am unable to find a solution from the existing questions & answers. I have created an html file which I think will have bootstrap functionality by linking to the CDN. It has a link to the JQuery CDN as well.
Well ... I just noticed that the Bootstrap styles are not loading at all. I am not sure why.
Nonetheless, I am assuming that fix will be relatively minor, but I have been struggling for much longer than that to figure out why the Popover is not working.
Please, if you are answering, make sure you are referencing the Bootstrap 3 rules.
note: the structure of the below code was taken straight from the Bootstrap website.
Without further ado !
Here's the code.
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 101 Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="row">
<div class="btn-group-vertical">
1
2
3
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://code.jquery.com/jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
<script>
$('.btn').popover();
</script>
</body>
</html>
You need to add http: to this link -
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
So this is the answer:
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>

jQuery and all .js files not working locally, only externally

I've got a strange problem. I'm coding a website and inlcuding jQuery and some plugins, that are stored in 'js' folder. When I try to open it through a browser jQuery, plugins and all my custom scripts aren't working. Maybe it's somehing with my code, but don't think so. Of course when I inlude jQuery externally (Google API's) it works, but got some plugins and scripts which aren't hosted elsewhere. Here's my 'head' tag.
<title>TOMTRANS - International Transport</title>
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />
<!-- S3Slider CSS -->
<link rel="stylesheet" type="text/css" href="css/s3slider.css" media="screen" />
<!-- jQuery -->
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<!-- jQuery Effects -->
<script type="text/javascript" src="js/functions.js"></script>
<!-- S3Slider -->
<script type="text/javascript" src="js/s3Slider.js"></script>
<!-- S3Slider Init -->
<script type="text/javascript">
$(function() {
$('#s3slider').s3Slider({
timeOut : 3000,
});
});
</script>
<!-- HTML5 Shiv -->
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
By locally do you mean a local web server (i.e. http://localhost:12345/) or the file system (i.e. file:///C:/Users/John/Desktop/hello.htm)? If it's the latter, then it's probably the security settings. Some browsers block scripts from the file system by default.
Try to do
"./js/..."
I think it will work as with external jquery.
Thanks
Ok I have solved my problem. It's my IDE fault - Aptana Studio 3. This bug occured because I didn't upload hidden .project file, while I copied it through default file browser (Ubuntu's Nautilus). When I used built-in AS3 ftp manager it also copied .project file, and now it works.
I know this thread is old, but I have't found the answer to this very annoying problem so I am adding my solution.
If your physical folder path includes an underscore, it will fail.
So, if you dropped your website to lets say C:\MyRoot\MyFolder_2\WebSite1\ then it won't work. however, if you remove the underscore and it becomes C:\MyRoot\MyFolder2\WebSite1\ it will suddenly work and jQuery will suddenly be loaded.

Categories

Resources