连接到数据库PhoneGap

时间:2013-07-02 19:11:48

标签: javascript cordova

我现在已经谷歌搜索了3个小时的答案,但似乎没有什么对我有用。什么都没发生。 db.php工作得很好。 javascript代码应该打印出数据库内容。我有这段代码:

$('#Puslapis').live('puslapisrodyti', function(event)) {
var $this = $(this);  
$.getJSON('localhost/pirmas/db.php', function (response) {
    var output = [];      
    if (response.status == 'Prisijungiau') { 
        for (var key in response.items) {          
             output.push('<li>' + response.items[key] + '</li>');
        }
    } else {
        output.push('<li>Prisijungimas nepavyko</li>');
    }
    $this.children('[data-role="content"]').append('<ul data-role="listview">' + output.join('') + '</ul>').trigger('create');
});

});

db.php中:

<?php
$connection = mysql_connect("localhost", "root", ""); 
$db = mysql_select_db("events", $connection); 
$query = mysql_query("SELECT * FROM events WHERE name ='Koncertas ZJBS.'", $connection) or trigger_error(mysql_error());
$output = array();

if (mysql_affected_rows() > 0) { 
while ($row = mysql_fetch_assoc($query)) {        
    $output[] = $row;
}
echo json_encode(array('status' => 'Prisijungiau', 'items' => $output));

} else {
echo json_encode(array('status' => 'ivyko klaida', 'items' => $output));
}

?>

HTML:

    <!DOCTYPE html>
<html>
<title>Renginiai</title>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="cordova/cordova.js"></script>
    <script type="text/javascript" charset="utf-8" src="connect.js"></script>

</head>
<body>
    <!-- Start of first page I -->
    <div data-role="page" id="page1">

        <!-- Header -->
        <div data-role="header">
            <h1>HAHAHA</h1>

        </div><!-- /header -->

        <!-- Content    -->
        <div data-role="content">
            <h3>blabla</h3>
            <p>
                blablabla
            </p>
        </div><!-- /content -->

        <!-- footer -->
        <div data-role="footer">
            <h4>&copy; 2013 </h4>
        </div><!-- /footer -->
    </div><!-- /page -->

</body>
</html>

0 个答案:

没有答案