我对 Framework7 还很陌生。我想使用 AJAX 从数据库中获取数据。它在浏览器上按预期工作,我可以获取数据并将其显示在 HTML 文件上,尽管当我将其转换为 apk(使用 Cordova)时无法显示任何数据。我正在使用外部数据库进行测试。PHP代码:$db['db_host'] = 'remotemysql.com';$db['db_user'] = 'user';$db['db_pass'] = 'pass';$db['db_name'] = 'name';foreach ( $db as $key => $value ) { define( strtoupper( $key ), $value );}$connection = mysqli_connect( DB_HOST, DB_USER, DB_PASS, DB_NAME );if ( !$connection ) { die( 'database failed');}$result = mysqli_query($connection,"SELECT * FROM users_details WHERE user_id = 1");$rows = array();while($row = mysqli_fetch_assoc($result)) { $rows[] = $row;}print json_encode($rows);HTML/AJAX 请求:<template><div class="page no-navbar home-user-page"> <div class="page-content home-user-page-content"> <div class="user-details-box"> <div class="user-details"> <div id="user-name"></div> <div id="user-title"></div> </div> <div class="user-chart-outer-box"> <div id="user-point"></div> <div id="user-level"></div> </div> </div> </div></div></template><script>return { on: { pageInit: function() { app.request.get('comps/get_user.php', function(response) { dataJSON = JSON.parse( response ); let user_name = dataJSON[0].user_name; let user_title = dataJSON[0].user_title; let user_points = dataJSON[0].user_points; let level = Math.ceil( user_points / 200 ); $( '#user-name' ).html( user_name ); $( '#user-title' ).html( user_title ); $( '#user-point' ).html( user_points ); $( '#user-level' ).html( "Level " + level ); }); } }}</script>提前致谢,
1 回答
- 1 回答
- 0 关注
- 184 浏览
添加回答
举报
0/150
提交
取消