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,
AJAXPHPJavaScriptjQuery

Avatar of undefined
Last Comment
Julian Hansen
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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Pravin Bnakar

ASKER

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.
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo