我正在尝试将文件和一些数据上传到服务器。在查看一些示例并在此处回答另一个问题后,使用了以下javascript。
html按钮
<button onclick="SendData()">Send</button>
Javascript代码
function SendData(){
// data gathering code above
var options = new FileUploadOptions();
options.fileKey = "logo"; options.fileName = imgurl.substr(fileURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg"; options.params = data;
var ft = new FileTransfer();
ft.upload(imgurl, encodeURI(GetWebServiceUrl()), win, fail, options);
} // Send data function
var win = function (r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
var fail = function (error) {
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
function IsDataValid()
{
var valid = true;
$(".required").each(function(){
if($.trim($(this).val()) == '')
{
alert ('One of the required field seems empty: ' + $(this).prop('id'));
valid = false;
return false;
}
});
return valid;
}
$("#buisnessimage").click(function(){
GetImage();
});
function GetImage()
{
navigator.camera.getPicture(onSuccess, onFail, {
destinationType: Camera.DestinationType.FILE_URI,
sourceType : Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit : true,
encodingType: Camera.EncodingType.JPEG});
}
function onSuccess(imageURI) {
imgurl = imageURI;
$("#buisnessimage").prop('src', imageURI);
}
function onFail(message) {
alert('Failed because: ' + message);
}
但在调用时,没有任何反应。我在Genymotion模拟器上测试并使用eclipse在本地编译。有cordova 2.9.0
任何帮助表示赞赏。