Tuesday, January 10, 2017

How submit or insert data and files using JQuery Ajax ?

Step : 1 create Index.php file
<form id="data" method="post" enctype="multipart/form-data">
<td><input type="text" name="firstName" value="" /></td>
<td><input type="text" name="lastName" value="" /></td>
<td><input name="image" type="file" /></td>
<td colspan="2"><input type="submit" name="submit" value="Submit" /></td>
<div id="response"></div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    var formData = new FormData($(this)[0]);
        url: "data.php",
        type: 'POST',
        data: formData,
        async: false,
        success: function (data) {
        cache: false,
        contentType: false,
        processData: false
    return false;

Step : 2 create data.php file
echo "<pre>";
echo "<pre>";
print_r($_POST );
/// Put here your logic for insert and uploading code.

1 comment:

rathoddhirendra.blogspot.com-Google pagerank and Worth