fixing one typo and making string formatting consistent.
[oweals/karmaworld.git] / karmaworld / assets / js / setup-ajax.js
1 function setupAjax(){
2   // Assumes variable csrf_token is made available
3   // by embedding document
4   $.ajaxSetup({
5     beforeSend: function(xhr, settings) {
6       if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
7         // Only send the token to relative URLs i.e. locally.
8         xhr.setRequestHeader("X-CSRFToken", csrf_token);
9         console.log("preparing request to " + settings.url);
10       }
11     }
12   });
13 }
14
15 $(function() {
16   setupAjax();
17 });