JQuery ajax提交form表单实现文件上传

原文链接https://www.jianshu.com/p/775cce61bfe5

 

JQuery ajax提交form表单实现文件上传

lihao_李浩 关注

2017.08.04 15:15* 字数 0 阅读 4172评论 0喜欢 1

<!DOCTYPE html>

<html>

 

<head>

<title></title>

<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>

</head>

 

<body>

<form id="tf">

<input type="file" name="file" />

<input type="text" name="username" />

<input type="button" value="提" οnclick="test();" />

</form>

<script type="text/javascript">

function test() {

var form = new FormData(document.getElementById("tf"));

$.ajax({

url: "http://192.168.10.133:8080/ktl/resource/getSourceData",

type: "post",

data: form,

processData: false,

contentType: false,

success: function(data) {

console.log(data);

},

error: function(e) {

console.log(e);

}

});

}

</script>

</body>

 

</html>

 

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...