如何在Phone Gap上运行php文件?
我需要运行一些php文件与我的应用程序,我上传到我的网站。我在这里读过一篇文章,我对我的文件做了同样的事情,但是我的php文件使用的是ajax,所以我无法运行它。我尝试了所有可能的方法,但还是错了 search.html通过js创建一个链接,并将该链接传递给get_data.php,并在带有results标记的同一页面中显示结果 search.html如何在Phone Gap上运行php文件?,php,ajax,mobile,cordova,Php,Ajax,Mobile,Cordova,我需要运行一些php文件与我的应用程序,我上传到我的网站。我在这里读过一篇文章,我对我的文件做了同样的事情,但是我的php文件使用的是ajax,所以我无法运行它。我尝试了所有可能的方法,但还是错了 search.html通过js创建一个链接,并将该链接传递给get_data.php,并在带有results标记的同一页面中显示结果 search.html function abc(target_url) { target_url = target_url||(generate_url(
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>
";
}
?>使用ajax您尝试的方法就是我建议的方法。您试图在不使用框架的情况下执行ajax请求,如果您在站点的其他任何地方都不使用框架,我认为这是减少站点加载时间的一个好主意。但是您在尝试实现ajax的过程中遇到了一些有趣的事情 如果你不打算使用一些框架,我建议如下 我注意到你在评论中提到 $'content'。加载 这是指使用jQuery将内容加载到页面中。查看您在上面提供的示例代码,我看不出您实际上在哪里导入了jQuery。首先导入,然后尝试使用该代码。另外,我建议使用$.ajax{}而不是$content.loadurl
$.ajax({
url: "http://www.example.com/test.php",
success: function(x){
$("#results").html(x);
}
});
有关使用jQuery框架执行ajax请求的更多信息,请访问我认为PhoneGap不允许您在手机上运行PHP。。。您需要在自己的服务器上托管PHP并进行设置,以便可以从PhoneGap应用程序向其发出XHR请求。这就是我所说的。你不能在手机上运行PHP,我的PHP文件不能在服务器上运行。我很难把它们连接起来。在另一个帖子上,它说要用这样的东西。但它不起作用内容“.load”http://www.example.com/test.php';