0

I am just trying to send a document through array into a ajax call.

$(document).ready(function(){
$('#submit').click(function(){
var a=$('#name').val();
alert(a)
var b=$('#document').val();
alert(b)
// var array = {};
        // arry = {
          //   a: $('#name').val(),
            // b: $('#document').val(),
          //   
        // }
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="name">
<input type="file" id="document">
<input type="button" id="submit" value="click me">

Here I can able to send input type="text" value.Coming to input type="file" I am getting only path of loaded file.
enter image description here
How can I convert it to a document?

user7397787
  • 1,410
  • 7
  • 28
  • 42
  • Possible duplicate of [Sending multipart/formdata with jQuery.ajax](http://stackoverflow.com/questions/5392344/sending-multipart-formdata-with-jquery-ajax) – Alive to die - Anant Apr 12 '17 at 07:14
  • To upload a file's binary data to the server you need to use a `form` element and submit that, or make your own AJAX request. If you instead want to read the file on the client, you can use a `FileReader`. – Rory McCrossan Apr 12 '17 at 07:14

1 Answers1

0

This solved my problem

$(document).ready(function(){
$('#submit').click(function(){
var a=$('#name').val();
alert(a)
var b=$('#document').val();
alert(b)
// var array = {};
        // arry = {
          //   a: $('#name').val(),
            // b: $('#document').files[0]
          //   
        // }
});
});
user7397787
  • 1,410
  • 7
  • 28
  • 42