[英]I want to send Image to database using ajax or any other method
我想使用ajax或任何其他方法將圖像發送到數據庫。 以下是我使用過的img標簽,這是我使用過的表單,並且使用了ajax請求發送表單數據,以及如何使用ajax請求將img發送到spring boot后端。
ajax請求(不包含圖像)
函數save(){
if ((($("#lbl_firstname").html()) === " ") && (($("#lbl_lastname").html()) === " ") &&
(($("#lbl_username").html()) === " ") && (($("#lbl_password").html()) === " ") &&
(($("#lbl_retype_password").html()) === " ") && (($("#lbl_birthDate").html()) === " ") &&
(($("#lbl_email_address").html()) === " ") && (($("#lbl_phone_number").html()) === " ")) {
var postObj = {};
postObj['username'] = $('#username').val();
postObj['password'] = $('#password').val();
postObj['email_address'] = $('#email_address').val();
postObj['first_name'] = $('#firstname').val();
postObj['last_name'] = $('#lastname').val();
postObj['dob'] = $('#birthDate').val();
postObj['phone_number'] = $('#phone_number').val();
postObj['gender'] = $('#gender').val();
$.ajax({
url: 'http://localhost:8080/project_name/save/login_user',
data: postObj,
dataType: 'json',
type: 'POST',
success: function(data) {
}
});
請嘗試Ajax表單提交
$("#form_id").on('submit', (function(e) {
e.preventDefault();
$.ajax({
url: "URL",
type: "POST",
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
success: function(data) {
}
})
}));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.