这里用的 html5 FormData
<input type="file" id="Filename" name="Filename" class="mytext" style="width:50%;" />
<input type="button" value="上传" οnclick="Upload1()" />
function Upload1()
{
if ($("#Filename")[0].files[0] == null)
{
alert("请选择文件上传");
return;
}
var formData = new FormData();
formData.append("allfiles", $("#Filename")[0].files[0]);
formData.append("__RequestVerificationToken", $("input[name='__RequestVerificationToken']").val());//验证
$.ajax({
url: "自己的url",
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function (responseStr,err) {
if (responseStr.result === "ok") {
alert("上传成功");
} else {
alert(responseStr.msg);
}
},
error: function (responseStr) {
alert("网络异常");
}