0

I am using ajax and jquery to submit the form. But it does not work. I am using following html form and jquery. To do this I want to use jQuery Ajax, but I don't know how to send the image with Ajax to PHP. Please Help me.

<form id="data" action="" method="post" enctype="multipart/form-data">
    <table style="width:630px;float:left;padding:10px;padding-top:30px;">
        <tr>
            <td class="text_label">Name</td>
            <td style="padding:10px;padding-right:20px;">:</td>
            <td>
                <input type="text" id="name" name="name" class="text_box" value="<?php echo   $name;?>" />
            </td>
        </tr>
        <tr>
            <td class="text_label">Upload Image</td>
            <td style="padding:10px;padding-right:20px;">:</td>
            <td>
                <input type="file" id="image" name="image" />
            </td>
        </tr>
        <tr>
            <td class="text_label"></td>
            <td style="padding:10px;padding-right:20px;"></td>
            <td>
                <input type="button" value="Update" class="btn_upd" onclick="update_stdDetails();" />
            </td>
        </tr>
    </table>
</form>

My jquery is

function update_stdDetails() {
    var formData = new FormData($(this)[0]);
    $.ajax({
        url: 'ajax/update_stdDetails.php',
        type: 'POST',
        data: formData,
        async: false,
        success: function (data) {
            alert(data)
        },
        cache: false,
        contentType: false,
        processData: false
    });
}
r0m4n
  • 3,474
  • 3
  • 34
  • 43
user2986106
  • 73
  • 1
  • 3
  • 10
  • possible duplicate of [Uploading both data and files in one form using Ajax?](http://stackoverflow.com/questions/10899384/uploading-both-data-and-files-in-one-form-using-ajax) – waki Dec 22 '14 at 04:05
  • How it possible on button onclick event by calling a function in js – user2986106 Dec 22 '14 at 04:09
  • replace `button` to `submit`, remove event `onclick`, do as url above – waki Dec 22 '14 at 04:22

0 Answers0