ajax 怎么获取input,获取<input type =“file”>内容在Ajax中

我想在用户提交之前验证通过Ajax上传的文件。我确定它是一个.txt或JavaScript中的.csv,然后我想打电话给我的控制器来验证它是否符合我们的CSV标准。获取内容在Ajax中

我:

function validateFile() {

var file = document.getElementById("csvFile");

var extension = file.value.split('.').pop();

if (extension != "csv" && extension != "txt") {

alert("A .csv or .txt file is required for upload");

return false;

}

$.ajax({

url: '@Url.Action("ValidateCSV","UploadCSV")',

type: "POST",

data: { file: document.getElementById("csvFile") }, //unclear here

success: function() {

alert("success");

},

error: function (error) {

alert("failed:" + error);

}

});

}

为Ajax数据,我怎么去得到HttpPostedFileBase控制器从文件希望?我希望在允许用户提交之前进行所有验证。我不是说我“允许”为任何指导做到这一点

三江源100%

+2

无法上传通过AJAX的文件。参见[这个答案详细信息](http://stackoverflow.com/a/6462673/1199711)。 –

+0

你是否简单地试图验证该文件以.txt和.csv结尾,然后将其提交上传? –

+0

否ajax控制器进行深度验证(验证标题,类型等) –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<td contenteditable="true" id="cell_1_1"><input type="text" oninput="filterTable(1)" placeholder="aoiStep" id="input_1_1"></td> <td contenteditable="true" id="cell_1_2"><input type="text" oninput="filterTable(2)" placeholder="defectType" id="input_1_2"></td> <td contenteditable="true" id="cell_1_3"><input type="text" oninput="filterTable(3)" placeholder="layerCode" id="input_1_3"></td> <td contenteditable="true" id="cell_1_4"><input type="text" oninput="filterTable(4)" placeholder="type"id="input_1_4"></td> <td contenteditable="true" id="cell_1_5"><input type="text" oninput="filterTable(5)" placeholder="dpet" id="input_1_5"></td> <td contenteditable="true" id="cell_1_6"><input type="text" oninput="filterTable(6)" placeholder="subcode" id="input_1_6"></td> <td contenteditable="true" id="cell_1_7"><input type="text" placeholder="codeDescription" id="input_1_7"></td> <td contenteditable="true" id="cell_1_8">image1</td> <td contenteditable="true" id="cell_1_9">image2</td> <td contenteditable="true" id="cell_1_10">image3</td> <td contenteditable="true" id="cell_1_11">image4</td> <td contenteditable="true" id="cell_1_12">image5</td> <td contenteditable="true" id="cell_1_13"><input type="text" placeholder="determination_rule"id="input_1_8"></td> </tr> </thead> <tbody> <tr> <td contenteditable="true">ACT</td> <td contenteditable="true">Particle</td> <td contenteditable="true">ACT</td> <td contenteditable="true">Particle</td> <td contenteditable="true">ACT</td> <td contenteditable="true">Particle</td> <td contenteditable="true">ACT</td> <td> <input type="file" onchange="previewImage(this)" onclick="showPopup(this.src)"style="width: 100px; height: auto;" > </td> <td> <input type="file" onchange="previewImage(this)"onclick="showPopup(this.src)" style="width: 100px; height: auto;"> </td> <td> <input type="file" onchange="previewImage(this)" onclick="showPopup(this.src)"style="width: 100px; height: auto;"> </td> <td> <input type="file" onchange="previewImage(this)" onclick="showPopup(this.src)"style="width: 100px; height: auto;"> </td> <td> <input type="file" onchange="previewImage(this)" onclick="showPopup(this.src)"style="width: 100px; height: auto;"> </td> <td contenteditable="true">Particle</td>我在网页对这些表格内容进行编辑后需要对HPHstudy创建的数据库进行写入、删除、查询、修改等操作需要怎么处理
07-22

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值