navigator.contacts.find既不调用onSuccess也不调用onError

时间:2012-10-02 13:59:00

标签: mobile contacts navigator

我两次调用getcontacts函数。首先是我启动应用程序,第二次(仅用于测试)在子页面中。两者都不起作用。它不会调用OnSuccess或onError,因为没有显示警报。

我的标题:

        <head>
    <meta name="viewport" content="width=deviceWidth; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=0;"/>
    <title>Blabla</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="css/styles.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="js/jquery.mobile-1.0a2.min.css" />

    <script src="js/jquery-1.4.4.min.js"></script>
    <script src="js/jquery.mobile-1.0a2.min.js"></script>
    <script src="js/phonegap.js"></script>

<!-- Finde Kontakte-->

    var phone_contacts;

    function getContacts() {

        var options = new ContactFindOptions();
        // Falls Filter gwünscht        
        options.filter=""; 
        options.multiple=true; 

        var fields = ["displayName", "name"];
        //alert('this alert is shown');
        navigator.contacts.find(fields, onSuccessContacts, onErrorContacts, options);
        alert('this alert isn't shown');

    }

    // onSuccess: Get a snapshot of the current contacts
    //
    function onSuccessContacts(contacts) {
        alert('Sucess');//is not shown

        for (var i=0; i<contacts.length; i++) {
           //Speicherung in Debugging Konsole
           // console.log("Display Name = " + contacts[i].displayName);

           //Kontakte nach Laden in globale Variable phone_contacts übetragen
           phone_contacts = contacts[i];

           //Speicherung der Kontakte in <p id="show_contacts">
           var element_contacts = document.getElementById('show_contacts');
        element.innerHTML += contacts[i].displayName;
        }
    }

    // onError: Failed to get the contacts
    //
    function onErrorContacts(contactError) {
            alert('Error');//isn't shown
        alert('onError!');
    }

    document.addEventListener('deviceready', doDeviceReady, false);

    function doDeviceReady () {
        // The following tells the app to fade #page1 in after the splash screen
        //get contacts
        getContacts();

        $('#page1').fadeIn(5000);

    }

});
    </script>
<!-- eof Finde Kontakte-->

</head>

2 个答案:

答案 0 :(得分:1)

变化

alert('this alert isn't shown');

alert('this alert isn\'t shown');

答案 1 :(得分:0)

您是否错过了此页面中的开头<script>标记?