我需要运行一些PHP文件与我的应用程序,我上传到我的网站。我在这里阅读了一篇文章,我为我的文件做了同样的事情,但是我的php文件与ajax一起工作,所以我无法运行它。我尝试了所有可能的方法,但我仍然错误。如何在手机差距上运行php文件?
search.html通过js创建链接并将此链接传递给get_data.php,并在results
标记的同一页面中显示结果。
search.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](https://developer.mozilla.org/En/HTTP_access_control),以便从你的PhoneGap应用程序对它进行XHR请求。 – Sathvik 2012-03-29 17:08:07
这就是我所说的。你不能在手机上运行PHP,我的PHP文件在服务器上。我无法连接它们。 在另一篇文章中说它使用类似的东西。但它不起作用。 '$('#content').load('http://www.example.com/test.php');' – 2012-03-29 20:20:08