Comments (3)
A few suggestions:
- Make sure you set
$.cors=true;
- If you're using jQuery Mobile, set
$.mobile.allowCrossDomainPages = true;
in your config on the `mobilinit' event. - If you control the server, look into using
Access-Control-Allow-Origin
to allow xhr access to your app.
from backbone.dualstorage.
It already works without CORS on PhoneGap by whitelisting the server. We do control the server, but have little time to fix it atm. Thanks for the tips.
This issue is strictly about the URL models point to. I want to keep the host out of the url, but still allow connection to both origin and a different domain.
from backbone.dualstorage.
Before you publicized this repository, I was working on something similar that might be helpful.
- I created an ApiConfig module that contains a
host
attribute (3 actually, based on which environment the app is running in). - I extended Models and Collections, adding two params -
service
andendpoint
attributes (host
could also be added here rather than in a config). - I set
Model.urlRoot
andCollection.url
to a function that builds the correct URL:
apiConfig[environment].host + '/' + object.service + '/' + object.endpoint
This gives me a flexible way to dynamically build the Model.urlRoot
and Collection.url
. The setup could be fleshed out to cover more edge cases, but it works for my needs right now.
How this relates to dualSync. When creating a new store, dualSync could simply look for object.service
and object.endpoint
. If either or both are found, the key for the new store would be [object.service] + '/' + [object.endpoint] + '/' guid
(square brackets represent optional values here). If neither are found, revert to object.url + '/' guid
.
dualSync would still work for people who aren't interested in adding host
, service
or endpoint
, since it would fall back to url
, while still supporting those who want a little more granularity.
Another option is to pass the key/endpoint inside options
, but I honestly don't like having to pack too much into options
in order to have things work correctly.
from backbone.dualstorage.
Related Issues (20)
- Save as dirty when Backbone model validation fails. HOT 2
- syncDirtyAndDestroyed() doesn't remove/clear ###_dirty in localStorage HOT 4
- If a collection has never had a model saved successfully to the server, it won't cache failed saves to localStorage HOT 8
- using .toJSON(options) instead of JSON.stringify in create()/update() store methods HOT 1
- "Uncaught TypeError: Cannot read property 'toString' of undefined" when saving without IDs HOT 1
- xhr 200 result of an error HOT 3
- Feature request: add a remote:"never" option per save HOT 4
- Fire event when syncDirtyAndDestroyed is finished HOT 1
- Offline changes with idAttribute seem to break page after refresh HOT 5
- Model.parse should not be called in dualsync HOT 3
- Parsing the string of ids for a collection each time a model updates blocks the main process HOT 1
- Would be better if syncDirty() returned a promise HOT 1
- model id not being set in Store.prototype.create HOT 5
- Destroyed model not being cleared after online sync HOT 2
- Dirty/Destroyed models not be cleared from localStorage after an online sync. HOT 1
- error function not defined HOT 5
- localForage support HOT 1
- QuotaExceededError HOT 1
- Model creation and modification race condition HOT 1
- Fetching remote changes before resolving dirty state HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backbone.dualstorage.