[英]Using FileReader.readAsDataUrl to upload image to Web Api service
[英]Upload file using own web service api
我尝试通过post和ajax上传文件,但是我只是更改了URL。
我不想这样更改URL
HTTP://本地主机:8080 / webportal.html文件= C%3A%5CUsers%5CVM9%5CDesktop%5Ctest5.txt
我要上传文件
这是我的代码...
HTML
<form id="uploadForm">
<label>Upload File:</label><br/>
<input name="file" type="file" />
<input type="submit" value="Submit" />
</form>
JavaScript
function UploadTestCase()
{
$(document).ready(function (e) {
$("#uploadForm").on('submit',(function(e) {
e.preventDefault();
var requireData = new FormData(this);
$.ajax({
url: "http://ip/webapi/upload?project=test",
type: "POST",
data: requireData,
contentType: false,
cache: false,
processData: false
})
return false;
}));
});
}
任何想法?
谢谢
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$('#uploaad_file').on('submit', function(e){
var data = new FormData(this);
e.preventDefault();
$.ajax({
url: 'index.php',
data : data,
processData:false,
contentType: false,
type: 'POST',
success: function(){
console.log(r);
},
error: function(){
console.log(arguments);
}
})
return false;
})
})
</script>
</head>
<body>
</body>
<form id="uploaad_file" enctype="">
<input type="file" name="file" id="file">
<input type="submit" value="upload">
</form>
</html>
我使用了这段代码。 它将表单数据成功发布到我的服务器端。 我可以用print_r查看$ _FILES数组。 一切看起来都很完美。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.