使用AJAX上传不起作用,表格数据为空

时间:2017-10-03 00:40:46

标签: javascript php jquery ajax

我正在尝试上传工作但由于某种原因,转到服务器文件的表单数据给我空了

表格代码:

<form id="uploadxlsx" name="uploadxlsx" enctype="multipart/form-data">
  <div class="form-group">
    <label>Excel File:</label>
    <input name="excelfile" id="excelfile" class="form-control" data-rule-required="true" data-msg-required="Choose File" type="file">
  </div>
  <div class="form-group">
    <button type="button" name="submit" class="btn btn-primary" onclick="sendFile();">Upload</button>
  </div>
</form>

以上

的JS代码
var xhr, hUploadSpeed;
function sendFile()
{
    document.getElementById("serverresponse").innerHTML = "";//clear previous server response

    var url = "upload.cfm";
    var formData = new FormData(document.getElementById("excelfile"));
    xhr = new XMLHttpRequest();

    xhr.open("POST", url, true);
    xhr.onreadystatechange = function()
    {
        if(xhr.readyState == 4 && xhr.status == 200)
        {
            alert(xhr.responseText);
            document.getElementById("serverresponse").innerHTML = xhr.responseText;
        }
    }
    xhr.send(formData); //Send to server
}

当转储服务器表单范围时,我得到了这个

http://prntscr.com/gsjbtw

这是请求标题图片

http://prntscr.com/gsjc3n

0 个答案:

没有答案