Last Updated: February 25, 2016
·
2.24K
· antillas21

Backbone and CORS

When building a Backbone-based JS app, if you need to connect to a third-party API with CORS support, don't forget to adjust jQuery's ajaxSetup to use XMLHttpRequest:

$.ajaxSetup({
    headers: { 'X-Requested-With' : 'XMLHttpRequest' }
});

This will save you some headaches when making requests to the API.