Getting CSRF token in external js file
<p>So I want to enable CSRF protection in my codeigniter app, but this means my js no longer works when its in an external file</p>

<pre><code>function saveToDatabase(editableObj,field,id) 
{

var pathArray = window.location.pathname.split( '/' );
var segment_3 = pathArray[3];
var save_data = { 
                    '&lt;?php echo $this-&gt;security-&gt;get_csrf_token_name(); ?&gt;' : '&lt;?php echo $this-&gt;security-&gt;get_csrf_hash(); ?&gt;',
                    'field':field,
                    'editedValue':editableObj.innerHTML,
                    'id':id

                };

$.ajax({
    url: segment_3+'/update',
    type: 'POST',
    data:save_data,
    success: function(){
        $(editableObj).addClass('bg-success');
    }        
});
}
</code></pre>

<p>I tested by copy pasting it into the view file, and it works perfectly fine.
So the problem is that this line</p>

<pre><code>'&lt;?php echo $this-&gt;security-&gt;get_csrf_token_name(); ?&gt;' : '&lt;?php echo $this-&gt;security-&gt;get_csrf_hash(); ?&gt;',
</code></pre>

<p>wont work in an external file? Is there any way to get that working? </p>