javascriptbackbone.jsparse-platformparse-javascript-sdk

ReferenceError: Backbone is not defined - Attempting to use Parse.com Javascript SDK


I'm trying to build a website, iOS app, and Android app for a school project, which requires me to have a server. I've decided to use Parse because it's free and I've used it for an iOS app. Although, I do not have experience with Parse's Javascript SDK.

Problem:
I have linked all the required libraries in my index.html file but when I launch the website I get the following error:

ReferenceError: Backbone is not defined.

Question:
What is causing this error? And how can I fix it?

From what I've read the SDK is built on top of Backbone.js and I must have Underscore.js linked because Backbone.js depends on it?

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>TutorMe - Home</title>

    <!-- Bootstrap -->
    <link href="./bootstrap-3.3.5/css/bootstrap.min.css" rel="stylesheet">

    <!-- 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.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

  <link href="./css/index.css" rel="stylesheet">

  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
  <script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.5.0.min.js"></script>

</head>

<body>

  <script type="text/javascript" src="./app/models/database.js"></script>

  <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script>
  <!-- Include all compiled plugins (below), or include individual files as needed -->
  <script src="./bootstrap-3.3.5/js/bootstrap.min.js"></script>
</body>

</html>

database.js

  Parse.initialize("X", "X");

  var Student = Backbone.Model.extend({

  });

  var StudentList = Backbone.Collection.extend({
    model: Student
  });

  var StudentListController = Backbone.View.extend({

    initialize: function() {
    }
  });

EDIT:

If I link backbone.js I get the following errors:

[Error] TypeError: undefined is not an object (evaluating 'i.extend')
    (anonymous function) (backbone-min.js, line 1)
[Error] ReferenceError: Can't find variable: Backbone
    global code (database.js, line 3)

Code:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.2/backbone-min.js"></script>

Solution

  • looks like you've not linked your backbone.js file

    <script src="/path/to/backbone.js"></script>
    

    or links to cdn

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.2/backbone-min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.2/backbone-min.map"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.2/backbone.js"></script>