Reputation: 289
Plz help me, I'm using the following code:
index.js:
var $ = require('./node_modules/jquery/dist/jquery.min');
var _ = require('./node_modules/underscore/underscore-min');
var Backbone = require('./node_modules/backbone/backbone-min');
require('./model/models');
run();
function run(){
var session = new ****.***.Models.CustomerSession();
session.save({
"authenticators": ["********","****"]
}).always(function(xhr){
do_something...
});
}
models.js:
**** = {};
****.*** = {};
****.***.Models = {};
var _ = require('../node_modules/underscore/underscore-min');
var Backbone = require('../node_modules/backbone/backbone-min');
/////////////MODELS/////////////
****.***.Models.CustomerSession = Backbone.Model.extend({
urlRoot : 'https://*****.****.com/api/***/customer_session/'
});
****.***.Models.Transaction = Backbone.Model.extend({
urlRoot : 'https://*****.****.com/api/***/transaction/'
});
****.***.Models.FaultType = Backbone.Model.extend({
urlRoot : 'https://*****.****.com/api/***/fault_type/'
});
****.***.Models.FaultTypeSet = Backbone.Model.extend({
urlRoot : 'https://*****.****.com/api/***/fault_type/'
});
****.***.Models.Task = Backbone.Model.extend({
urlRoot : 'https://*****.****.com/api/***/task/'
});
///////////////////////////////
And get the following ERROR: "Cannot read property 'ajax' of undefined"... This is all the code in the project except the node_modules libraries... I think that backbone don't recognize the $ sign, but I'm not sure and don't know what to do with the problem... Plz help me...
Here is the error log as I see it:
c:\ce\test_script\node_modules\backbone\backbone-min.js:1
h:"PATCH","delete":"DELETE",read:"GET"};e.ajax=function(){return e.$.ajax.appl
^
TypeError: Cannot read property 'ajax' of undefined
at Object.e.ajax (c:\ce\test_script\node_modules\backbone\backbone-min.js:1:14801)
at e.sync (c:\ce\test_script\node_modules\backbone\backbone-min.js:1:14518)
at i.extend.sync (c:\ce\test_script\node_modules\backbone\backbone-min.js:1:3208)
at i.extend.save (c:\ce\test_script\node_modules\backbone\backbone-min.js:1:5716)
at run (c:\ce\test_script\index.js:14:13)
at Object.<anonymous> (c:\ce\test_script\index.js:10:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
Process finished with exit code 8
Here is the error log when using backbone instead of backbone-min:
c:\ce\test_script\node_modules\backbone\backbone.js:1209
return Backbone.$.ajax.apply(Backbone.$, arguments);
^
TypeError: Cannot read property 'ajax' of undefined
at Object.Backbone.ajax (c:\ce\test_script\node_modules\backbone\backbone.js:1209:22)
at Backbone.sync (c:\ce\test_script\node_modules\backbone\backbone.js:1188:38)
at _.extend.sync (c:\ce\test_script\node_modules\backbone\backbone.js:286:28)
at _.extend.save (c:\ce\test_script\node_modules\backbone\backbone.js:493:18)
at run (c:\ce\test_script\index.js:17:13)
at Object.<anonymous> (c:\ce\test_script\index.js:10:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
Process finished with exit code 8
Upvotes: 1
Views: 3788
Reputation: 271
This was buried in the comments above, but I was having the same problem and setting
Backbone.$ = $
fixed the issue for me
Upvotes: 3