2

I use a JQuery library for cropping images , after click on crop button, Cropped image (result) is send back to HTML page via AJAX as "file data", Something like this:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIwAAA
CMCAYAAACuwEE+AAAgAElEQVR4nOy8d7hdVZ3/z/xmfH4z83y...

I want to sent this result to server as normal image file, but i don't know how to "attach" data to <input type="file" name="image" id="ajaxresult" hidden> .

I tried $("#ajaxresult").value(result); , but no luck. server says its null.

2 Answers 2

1
   var formData = new FormData($('#formid')[0]);
  formData.append('image', $('input[type=file]')[0].files[0]);
  $.ajax({
    url: path,
    data: formData,
    type: 'POST',
    contentType: false, // NEEDED, DON'T OMIT THIS (requires jQuery 1.6+)
    processData: false, // NEEDED, DON'T OMIT THIS
    success:function(){

    }
  });
Sign up to request clarification or add additional context in comments.

2 Comments

OK I made changes on ajax part as you mentioned, but still how to handle success result and send to input element?
@fredi you want assign the base64 encode data to #ajaxresult file filed you will use it this var image = new Image(); image.src = 'data:image/png;base64,iVBORw0K...'; document.body.appendChild(image);
0

first $data_one = explode(',',$var); add add after used base64_decode($data_one) used and try..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.