hello i'm developing in laravel 5.0
currently update image file on server in js. use plugin uploadify , works on google chrome.
but on mozilla firefox exception tokenmismatchexception.
i debug middleware (verifycsrftoken) , find
$token = chbevvpy5oye3p1ide4tzhfnjwezz7i6xnk9d03r
and
$request->session()->token() = ww2s9zf1xo82dxdmjxj0j5zubswkhvaderg20cmv
that's reason of exception. don't understand why both values isn't equals. js call
<script type="text/javascript"> <?php $timestamp = time();?> $(function() { $('#file_upload').uploadify({ 'formdata' : { 'method' : 'post', 'timestamp' : '{!! $timestamp !!}', '_token' : '{!! csrf_token() !!}' }, 'swf' : '{!!asset("js/uploadify/uploadify.swf")!!}', 'uploader' : '{!! asset("uploadify")!!}', 'buttontext' : 'votre logo' }); }); </script>
this code works on google chrome ...
edit : plugin uploadify uses flash
try use this. jquery set token header in ajax request header everytime don't need setup yourself.
// setting laravel 5 xsrf-token jquery.ajaxsetup({ headers: { 'x-xsrf-token': cookie('xsrf-token') } });
and here javascript cookie
function.
/** * cookie * @param {string} name * @returns {string} */ function cookie(name) { var cookie_start = document.cookie.indexof(name); var cookie_end = document.cookie.indexof(";", cookie_start); return cookie_start == -1 ? '' : decodeuricomponent(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length))); }
Comments
Post a Comment