5

我正在尝试使用电话间隙上传照片,但我总是收到未捕获的 ReferenceError。我试图将 cordova.js 放在 head 标签的开头,但没有成功。这是代码

索引.html

<head>
    <meta charset="utf-8">  
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <title>test</title>
    <script type="text/javascript" src="js/cordova-2.5.0.js"></script>      
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <link rel="stylesheet" type="text/css" href="css/jquery.mobile-1.3.0.min.css" />    
    <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="js/jquery.mobile-1.3.0.min.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
</head>

index.js

(function($){
    var self = $.mobile.test = {
        init : function(){
            $(document).on('pagebeforeshow', '#login', function(){
                $('#access').off('click').on('click',function(){
                    self.comprobarAcceso();
                });                 
            });
            $(document).on('pagebeforeshow', '#registrarse', function(){
                $('#registro').off('click').on('click',function(){
                    self.registrar();
                });                 
            }); 

            $(document).on('pagebeforeshow', '#nueva', function(){       
                console.log("nueva live...");
                $('#sacar-foto').off('click').on('click',function(){
                    self.capturarFoto();
                });                 
                $('#crear').off('click').on('click',function(){
                        self.crear();
                });
            });

        },
        crear: 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);
            }

            var options = new FileUploadOptions();
            options.fileKey="file";
            options.fileName=fileURI.substr(fileURI.lastIndexOf('/')+1);
            options.mimeType="text/plain";
            var params = {}; 
            params.value1 = "test"; 
            params.value2 = "param";

            options.params = params;

            var ft = new FileTransfer();
            ft.upload(fileURI, encodeURI("http://some.server.com/upload.php"), win, fail, options);             
        }


};

self.init();

})(jQuery);

我在 chrome 控制台上遇到错误: var options = new FileUploadOptions();

未捕获的 ReferenceError:未定义 FileUploadOptions。

似乎它没有加载cordoba库,但其他一切都正常工作,甚至用移动相机拍照。

请帮忙!

4

0 回答 0