I’m using WCF to create the REST backend for an app using backbone. WCF “smartly” tries to block XSS by returning JSON with a format of {d: “data”} where data contains the actual JSON response. How can I handle this in the Backbone.sync so that I can continue to use .save, .fetch, etc and my models will be updated correctly?
Share
You actually don’t need to do anything with Backbone.sync, instead just add a parse method to your models/collections http://documentcloud.github.com/backbone/#Model-parse
If “data” is in fact a string, you can parse it back into JSON with:
Not all browsers support the JSON.parse() method, so since I assume you are using jQuery, it might be safer to use
jQuery.parseJSON(response.d)rather thanJSON.parse(response.d)