Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone fetch() throws an Uncaught TypeError: Cannot read property 'ajax' of undefined

I am integrating BackBone on a new project. While I am somewhat familiar with BackBone, this will be my first attempt at creating a new project with it.

I setup a model and view, but am getting a console error that doesn't return any helfpul results on StackOverflow or Google. I'm hoping someone here can spot where I've gone wrong.

Here's the error, which occurs when I call thing.fetch()

Uncaught TypeError: Cannot read property 'ajax' of undefined 

And here's my CoffeeScript code:

Thing = Backbone.Model.extend
    name: 'thing'
    url: ->
        "/things/#{@id}"

ThingView = Backbone.Model.extend
    el: "#thing"
    render: ->
        console.log 'render', @$el

thing = new Thing(id: 1)
thing.fetch()

thingView = new ThingView()(model: Thing)
thingView.render()
like image 844
dw2 Avatar asked Feb 16 '23 16:02

dw2


1 Answers

UPDATE: Solved this on my own. Rookie mistake, not loading dependancies first. I realized that I had goofed and loaded Backbone before jQuery instead of after jQuery. The ajax method was an undefined property because jQuery didn't exist at that point in my code.

A lot of times the simple solution is the correct one. Thank you everyone who jumped in to help out!

like image 172
dw2 Avatar answered Apr 26 '23 02:04

dw2