1

I am using jQuery to upload an image and show a live preview. I have a form with id prescriptionform, file input with id scaninput1 and <div> for preview with id preview.

jQuery code:

$('#scaninput1').live('change', function() { 
    $("#preview").html('');
    $("#preview").html('<img src="scripts/loader.gif" alt="Uploading...."/>');
    $("#prescriptionform").ajaxForm({
        //alert("Hiiiiiii");
        target: '#preview'
    }).submit();
});

Code is running and I am uploading the image, but it's not submitting to ajaximage.php.

My HTML code:

<form name='prescriptionform' id="prescriptionform"  method='post'  enctype="multipart/form-data" action='ajaximage.php'>
    <div id="preview"></div>
    <input type="file" id="scaninput1" />
</form>
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
Rahul Singh
  • 1,614
  • 6
  • 22
  • 39

1 Answers1

1

You can't upload a file directly with an ajax form submit.

You will have to use some other technology to make this work.

How can I upload files asynchronously?

Community
  • 1
  • 1
BNL
  • 7,085
  • 4
  • 27
  • 32