我不明白为什么会收到此错误
未捕获的TypeError:无法读取未定义的属性'substr' 在onVehiclePhotoURISuccess
上
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
任何信息都将非常有用
下面的功能
我在下面指示的行上得到了错误。
function onVehiclePhotoURISuccess(imageURI,position, type) {
//Transfer the file to the server
var win = function (r) {
clearCache();
retries = 0;
$.mobile.loading( 'hide');
appAlert('Image transferred successfully.');
if (device.platform == 'android' || device.platform == 'Android' || device.platform == 'amazon-fireos' ) {
moveVehiclePic(imageURI,type);
} else {
//iOS
moveVehiclePiciOS(imageURI,type)
}
}
var fail = function (error) {
if (retries == 0) {
retries ++
setTimeout(function() {
onVehiclePhotoURISuccess(imageURI,type)
}, 1000)
} else {
retries = 0;
clearCache();
appAlert('Error uploading file. Code:'+ error.code+" Source:"+ error.source+" Target:"+ error.target);
}
}
var now=new Date();
var nowtime=now.timeNow();
nowtime=nowtime.replace(/:/g,"");
var filename = "VEH-"+type+localStorage.getItem("curIncidentId")+nowtime+".jpg";
curVehFileName=filename;
if (typeof position === "undefined" || position=="") {
var imageLat="";
var imageLng="";
} else {
var imageLat=position.coords.latitude;
var imageLng=position.coords.longitude;
}
var options = new FileUploadOptions();
options.fileKey = "file";
//=======`error line`=========
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
//================
options.mimeType = "image/jpeg";
options.params = { 'un': un ,
'secret': secret,
'imageType':type,
'fn': filename,
'xRef': localStorage.getItem("curIncidentId"),
'lat':imageLat,
'lng':imageLng };
$.mobile.loading( 'show', {
text: 'Uploading image...',
textVisible: true,
theme: 'a',
html: ""
});
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI(wsImageUploadURL), win, fail, options);
}
我设法找到 JSON 加载到 imageURI 中 现在我遇到了这个错误
未捕获的SyntaxError:JSON中位置1处的意外令牌i 在JSON.parse()
navigator.camera.getPicture(
function(imageInfo){
\\================
错误行========================
var oImage=JSON.parse(imageInfo)
\\=====================================================
var oMetaData=JSON.parse(oImage.json_metadata)
callBack(oImage.filename,position,p1,p2,p3);
}