Link to home
Start Free TrialLog in
Avatar of Pravin Bnakar
Pravin Bnakar

asked on

How to send image and data using ajax

I want to change profile information. There are 4 input box and 2 input file type.
i can't passing input box value and input file type image using Ajax,
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

What is the question?  Do you need to have an example of AJAX so you can build upon it for your app?  Or have you got something that is giving you an error?
Avatar of Pravin Bnakar
Pravin Bnakar

ASKER

I want post image and other data like user name via jquery AJAX to php server .
Here is My form
<form id="datafiles" method="post" enctype="multipart/form-data">
    <input type="text" name="first" value="Bob" />
    <input type="text" name="middle" value="James" />
    <input type="text" name="last" value="Smith" />
    <input name="image" type="file" />
    <button type="button" class="send_data">Submit</button>
</form>
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What does below line indicate :
var formData = new FormData($(this)[0]);
FormData gets all the data from a Form and makes it available for use in an AJAX request. You can read more about it here
https://developer.mozilla.org/en/docs/Web/API/FormData
EDIT
This differs from the jQuery serialize() method which does not serialize file data. FormData will serialize any files included in the form.