File phonegap图像上载完成后重定向

File phonegap图像上载完成后重定向,file,redirect,upload,File,Redirect,Upload,我有以下Phonegap的代码,可以将图像上传到PHP,这是可行的,但是当它完成后,我想重定向到index.html,尽管控件似乎永远不会返回到执行ft.upload()的位置-上传完成后,我需要做什么来重定向 <script type="text/javascript" charset="utf-8"> $(document).ready(function(){ $("#post_id").val("8"); var ls_token = get_token(

我有以下Phonegap的代码,可以将图像上传到PHP,这是可行的,但是当它完成后,我想重定向到index.html,尽管控件似乎永远不会返回到执行ft.upload()的位置-上传完成后,我需要做什么来重定向

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
    $("#post_id").val("8");
    var ls_token    = get_token("token");
    alert( ls_token );
    $("#token_id").val( ls_token );     
    //
    // Wait for PhoneGap to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // PhoneGap is ready
    //
    function onDeviceReady() {
        // Retrieve image file location from specified source
        navigator.camera.getPicture(uploadPhoto,
                                    function(message) { alert('get picture failed'); },
                                    { 
                                            quality: 50, 
                                            destinationType: navigator.camera.DestinationType.FILE_URI,
                                            sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY                                         }
        );
    }

    function uploadPhoto(imageURI) {
        var options = new FileUploadOptions();
        options.fileKey="file";
        //options.fileKey="img";
        options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
        options.mimeType="image/jpeg";
        var params = new Object();
        params.value1 = "test";
        params.value2 = "param";
        options.params = params;
        //options.chunkedMode = false;

        var ft = new FileTransfer();
        ft.upload(imageURI, "http://example.com/add_pictures/", win, fail, options );
        // similar behavior as an HTTP redirect
        window.location.replace("index.html");      // <-- not executed..

    }
    function win(r) {
        alert("Code = " + r.responseCode);
        alert("Response = " + r.response);
        console.log("Sent = " + r.bytesSent);
        // similar behavior as an HTTP redirect
        window.location.replace("index.html");      // <-- not executed..
    }

    function fail(error) {
        alert("An error has occurred: Code = " + error.code);
        alert("upload error source " + error.source);
        alert("upload error target " + error.target);
    }

}); 
</script>

$(文档).ready(函数(){
$(“post#u id”).val(“8”);
var ls_token=get_token(“token”);
警报(ls_令牌);
$(“#令牌_id”).val(ls#u令牌);
//
//等待PhoneGap加载
//
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
//PhoneGap已经准备好了
//
函数ondevicerady(){
//从指定源检索图像文件位置
navigator.camera.getPicture(上传照片,
函数(消息){alert('get picture failed');},
{ 
质量:50,
destinationType:navigator.camera.destinationType.FILE\u URI,
sourceType:navigator.camera.PictureSourceType.PHOTOLIBRARY}
);
}
函数上载照片(imageURI){
var options=new FileUploadOptions();
options.fileKey=“file”;
//options.fileKey=“img”;
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType=“image/jpeg”;
var params=新对象();
params.value1=“测试”;
params.value2=“param”;
options.params=参数;
//options.chunkedMode=false;
var ft=新文件传输();
ft.upload(imageURI,“http://example.com/add_pictures/“、胜利、失败、选择权);
//类似于HTTP重定向的行为

window.location.replace(“index.html”);//我自己对它进行了排序……最终,我使用“phonegap create..”创建了一个新项目,并更新了cordova版本。 在config.xml中,我添加了以下内容:

<edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="merge">
    <string>need camera access to take pictures</string>
</edit-config>

<edit-config target="NSPhotoLibraryUsageDescription" file="*-Info.plist" mode="merge">
    <string>need photo library access to get pictures from there</string>
</edit-config>

<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
    <string>need location access to find things nearby</string>
</edit-config>

<edit-config target="NSPhotoLibraryAddUsageDescription" file="*-Info.plist" mode="merge">
    <string>need photo library access to save pictures there</string>
</edit-config>
我不确定这其中哪一个真正解决了问题。我猜,当我在最初的项目中尝试一些东西时,有什么东西被改变或添加了,使它不安

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        var fd = new FormData();
        fd.append("file", file);
        fd.append("id","88");
 var posts = new XMLHttpRequest();
posts.onreadystatechange = function() { // listen for state changes
  if (posts.readyState == 4 && posts.status == 200) { // when completed we can move away
    window.location = "done.html";
  }
}
posts.open("POST",  'http://example.com/test1.php',   true);
posts.send(fd);