0

Im trying to build a mobile application from my webapp with PhoneGap. Everything works fine on desktop browser, but when I move files to PhoneGap the getJSON method doesn't seem to work. What could be the reason?

This is the code I use:

$('#employeeListPage').bind('pageinit', function(event) {
    getEmployeeList();
});

setInterval ( "getEmployeeList()", 10000 );
var vanhadata = "";

 function getEmployeeList() {
    $.getJSON(serviceURL + 'getemployees.php?autonumero=' + autonumero, function(data) {
       if(JSON.stringify(data) != JSON.stringify(vanhadata)){ 
            $('#employeeList li').remove();
            employees = data.key;
            $.each(employees, function(index, employee) {
                $('#employeeList').append('<li><a href="keikka.html?id=' + employee.IND + '">' +
                    '<h4>' + employee.OSO + '</h4>' +
                    '<img src="pics/' + employee.TILA + '.png"/>' +
                    '<p>' + employee.AIKA + '</p>' +'</a></li>');
        });
            $('#employeeList').listview('refresh');

            if(vanhadata != "")
               alert("Uusia keikkoja!");       
            vanhadata = data;
        }
    });
}  

Because it is cross-domain request I have also tried to use callback=? but that doesn't work either. How can i fix this?

4

1 に答える 1

0

この理由がわかりました。Phonegap にはホワイトリスト機能があるため、外部ホストを参照している場合は、「ExternalHosts」キーの下の PhoneGap.plist にホストを追加する必要があります。たとえば、Google に接続する場合は、「google.com」を externalHosts リストに追加する必要があります。

于 2012-05-16T04:47:04.863 に答える