0

Can I set urlRoot in my models as an absolute path so I can have my server side code (API) separated from my client side, html code? I am wondering if I can have my html js (backbone) code on my pc and use API which resides on live server environment.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
adrian F
  • 119
  • 1
  • 8

1 Answers1

1

Yes -- it's as simple as just setting to the urlRoot to whateever arbitrary URL you want:

var MyModel = Backbone.Model.extend({

   urlRoot: 'http://www.myserver.com/mypath'

});
Evan Hobbs
  • 3,552
  • 5
  • 30
  • 42
  • Well, i have my server side code on localhost and my html backbone application on desktop, and when i'm setting my urlRoot to http://localhost/api/etc i get this error: XMLHttpRequest cannot load http://localhost/api/public/tasks/1. No > 'Access-Control-Allow-Origin' header is present on the requested > resource. Origin 'null' is therefore not allowed access – adrian F Mar 01 '14 at 11:29
  • This is unrelated to Backbone or your original question -- please remark my answer as correct since it remains correct... The problem is that localhost is not set up to send a Access-Control-Allow-Origin header to the browser and your browser is therefore blocking the request. This may help you understand more :http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource-w if you're still having problems I suggest you ask a question about that. – Evan Hobbs Mar 01 '14 at 15:28
  • This may also help: http://stackoverflow.com/questions/5008944/how-to-add-an-access-control-allow-origin-header – Evan Hobbs Mar 01 '14 at 15:29