0

I want to send Image to database using ajax or any other method. following is the img tag i have used and this is a form which i have used and i have used ajax request to send form data how to send img to spring boot back end using ajax request.

ajax request ( not included the image )

function 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) {



            }
        });
Malinda Peiris
  • 583
  • 2
  • 8
  • 22

1 Answers1

1

Please try ajax form submition

$("#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) {
}
 })
}));
JIJOMON K.A
  • 1,290
  • 3
  • 12
  • 29