1
我調用getcontacts函數兩次。首先,當我啓動應用程序,第二次(僅用於測試)在子頁面中。兩者都不起作用。它不會調用OnSuccess或onError,因爲不顯示警報。navigator.contacts.find既不會調用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>
Actualy有它上面的地理位置的功能。所以在這個例子中我非常喜歡。腳本標記在我的代碼中。對於發佈錯誤的帖子感到抱歉。但是在這個假設下,所有的東西都必須有另一個錯誤? – user1714472