文件上传-提交表单
www.testaaa.com—跨域—请求—www.testbbb.com/file.php+
header(“Access-Control-Allow-Origin:*”);
<!DOCTYPE HTML>
<html>
<head>
<title>Upload</title>
<script src="jquery.1.12.min.js"></script>
</head>
<body>
<center>
<form id= "uploadForm" method= "post" enctype ="multipart/form-data">
<input type="text" name="title">
<input id="price" type="file" name="img">
</form>
<button id="upload">submit</button>
</center>
<script>
$(function(){
$('#upload').click(function(){
var formData = new FormData($( "#uploadForm" )[0]); //HTML5的FormData对象
$.ajax({
url: 'http://www.testbbb.com/file.php' ,
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
dataType: "json",
success: function (res) {
alert(res);
//array('title'=>title,'img'=>img);
}
});
});
})
</script>
</body>
</html>