【发布时间】:2012-03-29 06:16:55
【问题描述】:
我需要使用我的应用程序运行一些 php 文件,我将它们上传到我的网站。我在这里读过一篇文章,我对我的文件做了同样的事情,但是我的 php 文件正在使用 ajax,所以我无法运行它。我尝试了所有可能的方法,但我仍然错了。
search.html 通过 js 创建一个链接,并将这个链接传递给 get_data.php,并在带有results 标签的同一页面中显示结果。
搜索.html
function abc(target_url) {
target_url = target_url||(generate_url()||"http://nces.ed.gov/collegenavigator/?");
ajax = window.XMLHttpRequest?(new XMLHttpRequest()):(new ActiveXObject("Microsoft.XMLHttp"));
ajax.onreadystatechange=function() {
if(ajax.readyState===4) {
html_data = ajax.responseText;
//Do stuff with it like parsing, etc
//alert(html_data);
window.loading.style.visibility="hidden";
document.getElementById("results").innerHTML = html_data ||"We're sorry";
}
};
ajax.open("GET", "./get_data.php?url="+encodeURIComponent(target_url), true);
ajax.send(null);
window.loading.style.visibility="visible";
}
这是get_data.php
<?php
include_once('simple_html_dom.php');
$target_url = $_REQUEST["url"];
$html = new simple_html_dom();
$html->load_file($target_url);
$gokhan='arik';
#$anchors = array_diff($html->find('table[class=resultsTable] a'), $html->find('td[class=addbutton] a'));
$h2 = $html->find('table[class=resultsTable] h2');
$ipeds = $html->find('p[class=ipeds hoverID]');
foreach($html->find('div[id=ctl00_cphCollegeNavBody_ucResultsMain_divMsg]') as $nOfResults){
echo "<b>".strip_tags($nOfResults)."</b>";
}
$loca = $html->find('table[class=itables] tbody tr td[class=pbe]');
for($i=0;$i<count($h2);$i++) {
if(strip_tags($h2[$i])=="") continue;
#echo strip_tags(strtr($ipeds[$i], array(" "=>" ")));
$iped = explode(" ", strip_tags(strtr($ipeds[$i], array(" "=>" "))));
echo "<li data-theme='c' class='ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-btn-up-c'>
<div class='ui-btn-inner ui-li'>
<div class='ui-btn-text'>
<a href='search2.php?id=".$iped[2]."' class='ui-link-inherit'><h3 class='ui-li-heading'>".strip_tags($h2[$i])."</h3><p class='ui-li-desc'>".strip_tags(strtr($loca[$i], array('</h2>'=>'</h2> ')))."</p></a>
</div>
<span class='ui-icon ui-icon-arrow-r ui-icon-shadow'/>
</div>
</li>
";
}
?>
【问题讨论】:
-
我不认为
PhoneGap允许您在手机上运行 PHP...您需要在自己的服务器上托管 PHP 并设置 HTTP_Access_control,以便 XHR 请求可以从您的 PhoneGap 应用程序中进行。 -
我就是这么说的。你不能在手机上运行 PHP,我的 php 文件在服务器上。我很难连接它们。在另一篇文章中,它说要使用这样的东西。但它不工作。
$('#content').load('http://www.example.com/test.php');