[英]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.