IPhone Native App using PhoneGap and PHP

后端 未结 3 1472
难免孤独
难免孤独 2021-01-30 04:36

I want to develop an iPhone native app, that sync with a remote DB.Is it possible to develop this application using PhoneGap.If I use PhoneGap, how do I get data from an externa

3条回答
  •  庸人自扰
    2021-01-30 05:02

    I just compiled a PhoneGap app with PHP using Ajax to get content.

    First, load jQuery library at index.html head. At function onBodyLoad(), put the Ajax call for the PHP file:

    $('#content').load('http://www.example.com/test.php');
    

    at the HTML session, put the div id="content" where do you want to show content.

    PHP:

    for($i=1; $i<=10; $i++) {
        echo '

    I\'m a PHP Loop! Value: ' . $i . ' of 10.

    '; }

    HTML will print:

    I'm a PHP Loop! Value: 1 of 10.

    I'm a PHP Loop! Value: 2 of 10.

    I'm a PHP Loop! Value: 3 of 10.

    I'm a PHP Loop! Value: 4 of 10.

    I'm a PHP Loop! Value: 5 of 10.

    I'm a PHP Loop! Value: 6 of 10.

    I'm a PHP Loop! Value: 7 of 10.

    I'm a PHP Loop! Value: 8 of 10.

    I'm a PHP Loop! Value: 9 of 10.

    I'm a PHP Loop! Value: 10 of 10.

    You could also use

    $.get('test.php?name', function(data) {
        $('#content').html(data);
    });
    

    And your test.php could have something like:

    if (isset($_GET['name'])) {
        echo "Asked for name!";
    }
    

    With this, you can go on and make some nice stuff. I have one doubt on the subject: can I host external PHP files and deploy the app on app store? There's any restrictions about that?

提交回复
热议问题