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,
i can't passing input box value and input file type image using Ajax,
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?
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-da ta">
<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>
Here is My form
<form id="datafiles" method="post" enctype="multipart/form-da
<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</
</form>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
What does below line indicate :
var formData = new FormData($(this)[0]);
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.
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.