Kendo Upload - CSRF Token with kendo ui jquery

家住魔仙堡 提交于 2020-07-09 17:57:12

问题


how to add CSRF Token in kendoUpload

$("#image").kendoUpload({

    async: {
        saveUrl: "http://url",

    }
});

回答1:


<meta name="_token" content="{!! csrf_token() !!}" />

<input type="file" name="files" id="photos" />

   var token = $('meta[name="_token"]').attr('content');  

$("#photos").kendoUpload({
    async: {
        saveUrl: "http://url/save"
    },
    upload: onUpload
});

function onUpload(e) {
    var xhr = e.XMLHttpRequest;
    if (xhr) {
        xhr.addEventListener("readystatechange", function (e) {
            if (xhr.readyState == 1 /* OPENED */) {
                xhr.setRequestHeader("X-CSRF-TOKEN", token);
            }
        });
    }
}

document



来源:https://stackoverflow.com/questions/58988911/kendo-upload-csrf-token-with-kendo-ui-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!