I have following client code to upload image from phone
$("#placeorder").click(
function() {
if ($('#placeorderform').valid()) {
var formData = $('#placeorderform').serialize();
formData += "&uploaded="+ imgData;
$.ajax({
type : "POST",
url : _host+ "/addorder.php",
data : formData,
dataType : 'jsonp',
success : onSuccess,
error : onError
});
}
});
Server Side PHP (Not Working)
$encodedData = str_replace(' ','+',$_POST['uploaded']);
Server Side PHP ($_REQUEST or $_GET works; But for small images)
$encodedData = str_replace(' ','+',$_REQUEST['uploaded']);
what is the problem with my client code.
Additional observations:
I tried to inspect the request header and found surprising result. When i do above ajax in browser the data is received in POST. But from within Phonegap, even after explicit mention of type : “POST” the data is received in GET.
Can someone put some light on these behaviors 🙁 Something wrong with my Phonegap configuration?
So i got this working…Surprising find !!!
when i change dataType: ‘jsonp’ to (‘json’ or ‘text’) the formdata goes through in $_POST.
Only when the dataType: ‘jsonp’ the formdata for some unknow reasons goes through $_GET or $_REQUEST
Don’t know why this must be happening; But for now my problem is resolved with ‘json’.