mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	This should make it possible to use this AJAX setup code in logged-out code as well, which is necessary to use blueslip from portico pages.
		
			
				
	
	
		
			16 lines
		
	
	
		
			546 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			16 lines
		
	
	
		
			546 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
var csrf_token;
 | 
						|
$(function () {
 | 
						|
    // This requires that we used Jinja2's {% csrf_input %} somewhere on the page.
 | 
						|
    csrf_token = $('input[name="csrfmiddlewaretoken"]').attr('value');
 | 
						|
    window.csrf_token = csrf_token;
 | 
						|
 | 
						|
    $.ajaxSetup({
 | 
						|
        beforeSend: function (xhr, settings) {
 | 
						|
            if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
 | 
						|
                // Only send the token to relative URLs i.e. locally.
 | 
						|
                xhr.setRequestHeader("X-CSRFToken", csrf_token);
 | 
						|
            }
 | 
						|
        },
 | 
						|
    });
 | 
						|
});
 |