在 formdata 中添加图像并在 web 服务中使用 javascript
add image in formdata and use in webservice javascript
我正在创建一个网络应用程序,我想在其中添加图像我正在使用 javascript 和 FormData()
在网络服务中发送图像但是当我调试时我的表单数据没有显示任何数据
这是我的代码
var data = new FormData();
var ClientImage = $("#fl_ClientImage").get(0).files;
if (ClientImage.length > 0) {
data.append("ClientImage", ClientImage[0]);
}
console.log(data);
这里可能有什么错误?
$(document).ready(function (e) {
$("#uploadimage").on('submit',(function(e) {
e.preventDefault();
$.ajax({
url: "upload.php", // Url to which the request is send
type: "POST", // Type of request to be send, called as method
data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
contentType: false, // The content type used when sending data to the server.
cache: false, // To unable request pages to be cached
processData:false, // To send DOMDocument or non processed data file it is set to false
success: function(data) // A function to be called if request succeeds
{
console.log("data ",data);
}
});
}));
});
<form id="uploadimage" action="" method="post" enctype="multipart/form-data">
<div id="selectImage">
<label>Select Your Image</label><br/>
<input type="file" name="file" id="file" required />
<input type="submit" value="Upload" class="submit" />
</div>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
我正在使用 php 获取图像值。
<?php echo "<pre>";print_r($_FILES);die; ?>
我正在创建一个网络应用程序,我想在其中添加图像我正在使用 javascript 和 FormData()
在网络服务中发送图像但是当我调试时我的表单数据没有显示任何数据
这是我的代码
var data = new FormData();
var ClientImage = $("#fl_ClientImage").get(0).files;
if (ClientImage.length > 0) {
data.append("ClientImage", ClientImage[0]);
}
console.log(data);
这里可能有什么错误?
$(document).ready(function (e) {
$("#uploadimage").on('submit',(function(e) {
e.preventDefault();
$.ajax({
url: "upload.php", // Url to which the request is send
type: "POST", // Type of request to be send, called as method
data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
contentType: false, // The content type used when sending data to the server.
cache: false, // To unable request pages to be cached
processData:false, // To send DOMDocument or non processed data file it is set to false
success: function(data) // A function to be called if request succeeds
{
console.log("data ",data);
}
});
}));
});
<form id="uploadimage" action="" method="post" enctype="multipart/form-data">
<div id="selectImage">
<label>Select Your Image</label><br/>
<input type="file" name="file" id="file" required />
<input type="submit" value="Upload" class="submit" />
</div>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
我正在使用 php 获取图像值。
<?php echo "<pre>";print_r($_FILES);die; ?>