I am currently working on the framework for a project that we have split into a web client and server code. The client code uses a combination of require .js and backbone.js. I'm currently working on setting up the client/server communication, and ideally we'd like to be able to use backbone’s built in .sync functionality (and the fetch call built off of it) .
However, I'm running into an odd series of errors.
As the code executes, I'm getting the following error in the console. "Uncaught Error: A "url" property or function must be specified"
These are the related shims from our main.js
require.config({
paths: {
'jQueryBase': '../vendor/jquery-1.10.2/jquery-1.10.2',
'jQuery': '../vendor/jquery-ui-1.10.3/ui/jquery-ui',
'underscore': '../vendor/underscore/underscore',
'backbone': '../vendor/backbone/backbone',
'handlebars': '../vendor/handlebars/handlebars-v1.1.2 '
},
shim: {
'jQuery': {
exports: '$',
deps: ['jQueryBase']
},
'underscore': {
exports: '_'
},
'backbone': {
exports: 'Backbone',
deps: ['underscore', 'jQueryBase']
},
'handlebars': {
exports: 'Handlebars'
}
},
waitSeconds: 0
});
This is our dogModel.js
define(['backbone'],
function (Backbone) var DogModel = Backbone.Model.extend({
});
return DogModel;
});
This is our dogCollection.js
define {
('backbone',
'../models/dogModel'
J,
function (Backbone,
DogModel) {
var DogCollection = Backbone.Collection.extend({
model: DogModel,
url: '/dogs',
});
return DogCollection;
});
This is our dogData.js
define(['../collections/dogCollection',
'../models/dogModel'
],
function (DogCollection,
DogModel) {
var dogDataModule = {};
dogDataModule.dogList = new DogCollection();
//this request works
$.ajax(
type: "GET",
dataType: "json",
url: "http://localhost:7001/SERVICES/dogs",
success: function (data) {
dogDataArray = data;
for (var i = 0; i < dogDataArray.length; i++) {
var dogData = dogDataArray[i];
var dogModel = new DogModel();
dogModel.set(dogData);
dogDataModule.dogList.add(dogModel);
}
}
});
//this request doesn't
dogDataModule.dogList.sync('read', DogCollection, {
success: function () {
alert("success ");
},
error: function () {
alert("failure ");
}
};
return dogDataModule;
});
I've attempted to add a URL to directly to the options of the sync request, as so:
dogDataModule.dogList.sync('read', DogCollection, {
url: 'http://localhost:7001/SERVICES/dogs',
success: function () {
alert("success");
},
error: function () {
alert("failure "
};
});
But all this does is change the error to read "Uncaught TypeError : Object function (){ return parent.apply(this, arguments); } has no method 'trigger'".
I've also attempted to add "SERVICES/" and "../SERVICES/" in front of the collection's url property, or giving the full and explicit URL property (up to and including http://), but none of that has worked either.
Can anyone help me figure out why I am seeing this error?