Android 全局变量未定义phonegap
我正在phonegap中开发一个android应用程序,在这个应用程序中,我点击按钮,从设备的照片库中拍照。我在我的应用程序中显示它,然后会显示一个弹出窗口,询问我是否要确认将图像上载到服务器(我使用Filetransfer上载图像) 除了一件事,一切都很好。当我可以拍照时,我会显示它并上传它。现在的问题是,当我上传图片时,在我的win(r)函数中有一个变量“r.response”,我应该将它发送到服务器。这就是为什么我创建一个全局变量“imageServer”,它接受r.response的值,并从另一个函数调用它。但当我发出警报时,它告诉我未定义。这是我的密码Android 全局变量未定义phonegap,android,cordova,camera,Android,Cordova,Camera,我正在phonegap中开发一个android应用程序,在这个应用程序中,我点击按钮,从设备的照片库中拍照。我在我的应用程序中显示它,然后会显示一个弹出窗口,询问我是否要确认将图像上载到服务器(我使用Filetransfer上载图像) 除了一件事,一切都很好。当我可以拍照时,我会显示它并上传它。现在的问题是,当我上传图片时,在我的win(r)函数中有一个变量“r.response”,我应该将它发送到服务器。这就是为什么我创建一个全局变量“imageServer”,它接受r.response的值,
var imageServer;
function uploadPhoto(imageData)
{
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageData.substr(imageData.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
var params = {};
params.value1 = "test";
params.value2 = "param";
options.params = params;
var ft = new FileTransfer();
ft.upload(imageData, encodeURI("Server Url"), win, fail, options);
}
function win(r)
{
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
imageServer = r.response;
//alert(imageServer);// Here when i alert i should get the url of the picture
console.log("Sent = " + r.bytesSent);
}
function fail(error)
{
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
function SendServer()
{
alert(imageServer); // when i alert here i get undefined
var callDatasetPosition = JSON.stringify({'serviceName':"global_functions", 'methodName':'setPosition',"parameters":[imageServer]});// here when i see in server side , there is no url of image send
$.post('server url', callDatasetPosition, function(resp){}).done(function(data)
{
console.log(data);
alert(data);
});
}
你能帮帮我吗。非常感谢尝试localStorage.setItem(“imageServer”,r.bytesSent)和get in SendServer()函数alert(localStorage.getItem(“imageServer”))谢谢你的回答,我在alert alert(localStorage.getItem(“imageServer”)中试过了;我得到空值