I am unable to figure out the problem .I apology in advance if I have lack of knowledge and did silly mistakes. Here is my piece of code.
<!-- Piece of html -->
<div class="form-group">
<input class="form-control" placeholder="Enter Service image" id="edit_service_image-1" type="file" name="file_image">
</div>
<button type="button" class="btn btn-primary" onclick="processIt(<?php echo $service['service_id'];?>,'esi',document.getElementById('edit_service_image-1').files[0])">Edit</button>
The javascript function :->
function processIt(id,flag,inputvalue)
{
var filedata = new FormData();
filedata.append('imagefile', inputvalue);
filedata.append('id', id);
filedata.append('flag', flag);
$.ajax({
url: 'modify.php',
type: 'POST',
inputvalue: filedata,
contentType: false,
processData: false,
cache: false
}).success(function(msg) {
alert(msg);
});
}
Here is modify.php (Only test code)
<?php
if(isset($_REQUEST['flag']) && !empty($_REQUEST['flag']) && isset($_REQUEST['id']) && !empty($_REQUEST['id']) )
{
$flag = $_REQUEST['flag'];
$id = $_REQUEST['id'];
echo "Processed";
}
else
echo "Request not processed";
?>
So my problem is its always alerting "Request Not Processed", which means nothing is getting posted using ajax POST . I am confused, couldn't figure out the exact problem.
Edit
Another test code of modify.php
<?php
print_r($_FILES);
print_r($_POST);
?>
In this case the output is -->
Array{
}
Array{
}
SOLVED
Thanks to everybody who guided me Just a change in javascript worked . Here's the following changed code in processIt() function, which served my purpose->
function processIt(id,flag,inputvalue)
{
var filedata = new FormData();
filedata.append('imagefile', inputvalue);
filedata.append('id', id);
filedata.append('flag', flag);
$.ajax({
url: 'modify.php',
type: 'POST',
data: filedata, // Here instead of inputvalue it's changed to data
contentType: false,
processData: false,
cache: false
}).success(function(msg) {
alert(msg);
});
}