dtslobe4694 2013-12-18 16:12
浏览 55
已采纳

将php内容加载到Phonegap中

I am working with phonegap and dreamweaver to setup a small application but i am facing a problem as i am a new in phonegap.

I have an HTML5 file and my css file also the config.xml form my icon, splashscreen etc. Phonegap reads only the index.html and not the index.php file.

So i made a grab.php file to pull some data from my hosting. Localhost everything works great but when i am build the app it doesn't load the data...

Here is my html file and grab.php file.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<title>Celebrity.Com | Android App</title>
<link rel="stylesheet" type="text/css" href="mobile_css/style.css" media="all" />
<script type="text/javascript" src="js/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>

<script type="text/javascript">
$(document).ready(function() {
    $(".loa").load("grab.php");
});
</script>

</head>

<body>

<div class="headerHolder"><div class="logo"></div></div>
<div style="width:100%; height:20px; float:left; margin-bottom:1px;"></div>

<div class="loa" style="width:100%; padding-bottom:5px;">

<div style="clear:both;"></div>
</div>

</body>
</html>

And grab.php

<?php
require "connectiondb.php";
$bann = mysql_query ("SELECT * FROM info ORDER BY a_name");
while($bannerl = mysql_fetch_assoc($bann)) {
echo '
<div class="articleHolder">
<div class="imageholder"><img src="'.$bannerl['a_image'].'" width="180" height="120"/></div>
<div class="controlz"><span style="float:left;">'.$bannerl['a_name'].'</span><img style="width:65px; height:65px; float:right;" src="images/details.png" width="65" height="65" border="0"></div>
</div>';
}
?>

I tried to upload the grab.php file to my server and load it from here but i think that the policy doesn't let me to run, load files from other servers.

  • 写回答

1条回答 默认 最新

  • dqh1992 2013-12-18 16:16
    关注

    You need to put your host in a whitelist (http://docs.phonegap.com/en/1.9.0/guide_whitelist_index.md.html)

    Then you have to specify in Phonegap configuration your domain:

    Then you can make ajax requests, but you have to specify the domain, so needs to be something like:

    <script type="text/javascript">
    $(document).ready(function() {
        $(".loa").load("http://yourdomain.com/grab.php");
    });
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备