简体   繁体   English

如何使用剑道 ui 将 excel 文件上传到服务器

[英]How to upload excel file to server with kendo ui

i am trying to upload an excel file to my server with kendo ui but nothing happens.The problem is in js on var upload as the #kupload is null and i dont know why我正在尝试使用 kendo ui 将 excel 文件上传到我的服务器,但没有任何反应。问题出在 var upload 上的 js 中,因为#kupload 是 null,我不知道为什么

<div class="form-group">
<label for="kUpload">Select File for Upload </label> 
   <input type="file" id="kUpload"/>
 </div>

Upload上传

$(document).ready(function ()
{ $("#btn-kUpload").on("click", function (e) {
            e.preventDefault();


            var formData = new FormData();
            var upload = $("#kUpload").getKendoUpload();


            var files = upload.getFiles();
            formData.append('files', files[0].rawFile);

            // Send the request
            $.ajax({
                url: 'test.aspx/ImportExcel',
                type: 'POST',
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function (response) {
                    console.log(response);
                }
            });
        });

You don't need to use ajax if you are using kendo components, kendo upload has built-in ajax request for sending files to the server.如果您使用剑道组件,则不需要使用 ajax,剑道上传内置了 ajax 请求,用于向服务器发送文件。

NOTE : Generally every kendo component that communicates with server-side has own ajax function so you don't need to use $.ajax注意:通常每个与服务器端通信的剑道组件都有自己的 ajax function 所以你不需要使用 $.ajax

You only need to define saveUrl:您只需要定义 saveUrl:

    <input name="files" id="files" type="file" aria-label="files"/>

    $('#files').kendoUpload({
        async: {
            saveUrl: 'test.aspx/ImportExcel'
        },
        dropZone: '.drop-zone',
        multiple: true,
        clear: function () {

        },
        complete: function(){
         //This is called when all files are uploaded
        },
        success: function() {
         //This is called for every uploaded file
        },
        error: function () {

        },
        localization: {
            select: 'Upload file...'
        }
    });

Offical example: Upload component官方示例:上传组件

Check documentation: Kendo UI Upload检查文档: Kendo UI 上传

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM