简体   繁体   English

将 php 内容加载到 Phonegap

[英]Loading php content into 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.我正在使用 Phonegap 和 Dreamweaver 来设置一个小应用程序,但由于我是 Phonegap 的新手,所以我面临一个问题。

I have an HTML5 file and my CSS file also the config.xml form my icon, splash screen etc.我有一个 HTML5 文件和我的 CSS 文件还有 config.xml 形成我的图标、启动画面等。

Phonegap reads only the index.html and not the index.php file. Phonegap 只读取 index.html 而不是index.php文件。

So I made a grab.php file to pull some data from my hosting.所以我制作了一个grab.php文件来从我的主机中提取一些数据。 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.这是我的html文件和grab.php文件。

<!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

<?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.我试图将grab.php文件上传到我的服务器并从这里加载它,但我认为该策略不允许我运行,从其他服务器加载文件。

You need to put your host in a whitelist (http://docs.phonegap.com/en/1.9.0/guide_whitelist_index.md.html )您需要将您的主机放入白名单(http://docs.phonegap.com/en/1.9.0/guide_whitelist_index.md.html

Then you have to specify in Phonegap configuration your domain:然后您必须在 Phonegap 配置中指定您的域:

Then you can make ajax requests, but you have to specify the domain, so needs to be something like:然后就可以进行ajax请求了,但是必须指定域,所以需要是这样的:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM