Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在phonegap中上载文件后重定向_Javascript_Android_Cordova - Fatal编程技术网

Javascript 在phonegap中上载文件后重定向

Javascript 在phonegap中上载文件后重定向,javascript,android,cordova,Javascript,Android,Cordova,我的phonegap上传脚本工作得非常好。上传后,您会收到一条消息“请等待重定向”。我想知道如何添加重定向脚本,以便在上传后立即重定向到另一个页面 var deviceReady = false; /** * Take picture with camera */ function takePicture() { navigator.camera.getPicture( function(uri) {

我的phonegap上传脚本工作得非常好。上传后,您会收到一条消息“请等待重定向”。我想知道如何添加重定向脚本,以便在上传后立即重定向到另一个页面

    var deviceReady = false;

    /**
     * Take picture with camera
     */
    function takePicture() {
        navigator.camera.getPicture(
            function(uri) {
                var img = document.getElementById('camera_image');
                img.style.visibility = "visible";
                img.style.display = "block";
                img.src = uri;
                document.getElementById('camera_status').innerHTML = "Success";
            },
            function(e) {
                console.log("Error getting picture: " + e);
                document.getElementById('camera_status').innerHTML = "Error getting picture.";
            },
            { quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI});
    };

    /**
     * Select picture from library
     */
    function selectPicture() {
        navigator.camera.getPicture(
            function(uri) {
                var img = document.getElementById('camera_image');
                img.style.visibility = "visible";
                img.style.display = "block";
                img.src = uri;
                document.getElementById('camera_status').innerHTML = "Success";
            },
            function(e) {
                console.log("Error getting picture: " + e);
                document.getElementById('camera_status').innerHTML = "Error getting picture.";
            },
            { quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY});
    };

    /**
     * Upload current picture
     */
    function uploadPicture() {

        // Get URI of picture to upload
        var img = document.getElementById('camera_image');
        var imageURI = img.src;
        if (!imageURI || (img.style.display == "none")) {
            document.getElementById('camera_status').innerHTML = "Take picture or select picture from library first.";
            return;
        }

        // Verify server has been entered
        server = document.getElementById('serverUrl').value;
        if (server) {

            // Specify transfer options
            var options = new FileUploadOptions();
            options.fileKey="file";
            options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1)+'.jpg';
            options.mimeType="image/jpeg";
            options.chunkedMode = false;




options.params = {
            filename: window.localStorage.setItem("key", options.fileName)

        }


            // Transfer picture to server
            var ft = new FileTransfer();
            ft.upload(imageURI, "http://myphonegap.com/upload.php", function(r) {
        document.getElementById('camera_status').innerHTML = "Please wait redirecting";             
            }, function(error) {
                document.getElementById('camera_status').innerHTML = "Upload failed: Code = "+error.code;               
            }, options);
        }
    }

    /**
     * View pictures uploaded to the server
     */
    function viewUploadedPictures() {

        // Get server URL
        server = document.getElementById('serverUrl').value;
        if (server) {

            // Get HTML that lists all pictures on server using XHR 
            var xmlhttp = new XMLHttpRequest();

            // Callback function when XMLHttpRequest is ready
            xmlhttp.onreadystatechange=function(){
                if(xmlhttp.readyState === 4){

                    // HTML is returned, which has pictures to display
                    if (xmlhttp.status === 200) {
                        document.getElementById('server_images').innerHTML = xmlhttp.responseText;
                    }

                    // If error
                    else {
                        document.getElementById('server_images').innerHTML = "Error retrieving pictures from server.";
                    }
                }
            };
            xmlhttp.open("GET", server , true);
            xmlhttp.send();         
        }   
    }

    /**
     * Function called when page has finished loading.
     */
    function init() {
        document.addEventListener("deviceready", function() {deviceReady = true;}, false);
        window.setTimeout(function() {
            if (!deviceReady) {
                alert("Error: PhoneGap did not initialize.  Demo will not run correctly.");
            }
        },2000);
    }

只需在success函数的末尾执行页面转换。例如,在这一行之后:

document.getElementById('camera_status').innerHTML = "Please wait redirecting"; 
做:

或:


等等。

您现在使用的页面之间的转换是什么?jQuery和一个单页应用程序,还是只想显示另一个.html文件?首先,您应该问一下,他使用的是什么框架。通常,您将使用单页应用程序,并使用jQuery进行页面转换。那你的回答就没用了
window.location.href = "otherpage.html"
$('page1_div').hide();
$('page2_div').show();