-1

I've made a flie upload.php which uploads the .docx file to the server.It is working properly. Now I want to upload file without refreshing the page using the same php file. How can I call the php file using ajax ?? and how to show the message sent by upload.php ??

Kevin B
  • 94,570
  • 16
  • 163
  • 180
Suman Kumar
  • 27
  • 1
  • 1
  • 7
  • Possible duplicate of [How can I upload files asynchronously?](http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously) – Kevin B Oct 31 '16 at 21:37

1 Answers1

0

Try this:

<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" value="Upload" name="upload" />
</form>

<script>
 $('form').submit(function(e){
     e.preventDefault();
       $.ajax({
                type: "POST",
                url: "link/to/the/upload.php" ,
                data: ('form').serialize(),
                success : function(data) {
                    alert('Uploaded!');
                },
                fail: function(data) {
                    alert('failed to upload');
                    }
            });
    });
</script>
Okafor T Kosiso
  • 308
  • 3
  • 10