I want created a form to upload document by using POST method to call an API.
It did work well in desktop, but mobile browser totally doesn't work on the upload action.
Device : IPhone X - IOS 11.4
Mobile Browser: Google Chrome & Safari (both are the updated as now)
Html Code:
<form id="docsUpload">
<input type="hidden" name="token" value="aa">
<input type="file" class="upload-file" id="brFile" name="brFile" data-text="Find file">
<button id="submitBtn" class="btn btn-custom btn-upload" type="button">
<span name="langKey">Upload</span>
</button>
</form>
JQUERY Code:
$('#submitBtn').on('click', function (e) {
e.preventDefault();
var data = new FormData($('#docsUpload')[0]);
var newToken = data.get('token');
newToken = encodeURIComponent(newToken);
$.ajax({
url: host + 'uploadFile?token=' + newToken,
type: 'POST',
data: data,
cache: false,
dataType: 'json',
enctype: 'multipart/form-data',
processData: false, // Don't process the files
contentType: false, // Set content type to false as jQuery will tell the server its a query string request
success: function (response) {
console.log(response)
if (response.isUploadSuccess) {
return showResult('ok', 'uploadSuccess', response.uploadMessage);
}
return showResult('fail', 'uploadFail', response.uploadMessage);
}, error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
let errorMsg = JSON.stringify(jqXHR)
return showResult('fail', 'uploadFail', errorMsg + '<br>' + textStatus + '<br>' + errorThrown)
}
})
});
The above code is totally working fine in PC browser, but when run in mobile i always get the below error:
{"readyState":0,"status":0,"statusText":"error"}
Additional Info:
I am totally lost now.. Please help.
Thank you.