0

I have the following code

<div id=form>
    <div id=viewimage>
        <img src="placeholder.png">
    </div>
    <div id=upload>
        <form action="upload.php" method=POST enctype="multipart/form-data">
            <input type=file name=image>
            <input type=submit value=Upload>
        </form>
    </div>
</div>

I need the image to be uploaded and then the #viewimage div to be refreshed with the submitted picture. When the form submits, the upload.php will return a file name of the uploaded file. I think this is an ajax question, but im a complete noob when it comes to ajax/javascript, so i dont have the slightest idea how to proceed.

2
  • So, as neither uploading an image nor reloading a div via ajax is particulary rocket science, what have you tried so far? Commented Nov 1, 2009 at 11:40
  • No idea how to reload a div with ajax after an image upload. I'm not sure if i need to put in a delay to allow for the upload, or what. There are particulars at work and since javascript/ajax isn't my area of expertise I'm consulting the community at large for guidance. Commented Nov 1, 2009 at 11:45

1 Answer 1

1

If you want do do it in ajax, you should put your form inside an iframe, so when you upload the image, only a small part of the page (the form) is sent to your server.

After that, you can use upload.php response to get the name and path of uploaded image, and then you can just change the src of the img tag.

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

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.