2012-03-29 4 views
1

내 응용 프로그램과 함께 일부 PHP 파일을 실행해야하며이를 내 웹 사이트에 업로드했습니다. 여기에 기사를 읽었는데, 내 파일에 대해서도 똑같은 일을했지만 php 파일이 아약스와 함께 작동하기 때문에 실행할 수 없었다. 가능한 모든 방법을 시도했지만 여전히 오해가 있습니다.Phone Gap에서 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"; 


    } 

이 아약스 (방법은 당신이 시도)를 사용하여

<?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("&nbsp;"=>" "))); 
    $iped = explode(" ", strip_tags(strtr($ipeds[$i], array("&nbsp;"=>" ")))); 


    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> 
      "; 


} 

?>

+0

을 수행 할 jQuery를 프레임 워크를 사용하는 방법에 대한 자세한 내용은

$.ajax({ url: "http://www.example.com/test.php", success: function(x){ $("#results").html(x); } }); 

... 당신은 호스트해야합니다 PHP를 자신의 서버에 설치하고 [HTTP_Access_control] (https://developer.mozilla.org/En/HTTP_access_control)을 설정하면 PhoneGap 앱에서 XHR 요청을 할 수 있습니다. – Sathvik

+0

그건 내가 말한거야. 당신은 전화 PHP는 서버에서 내 PHP 파일을 실행할 수 없습니다. 나는 그들을 연결하는 데 문제가 있습니다. 다른 게시물에서는 이와 비슷한 것을 사용한다고합니다. 하지만 작동하지 않습니다. '$ ('#content') .load ('http://www.example.com/test.php'); –

답변

0

내가 제안하는 방법입니다 get_data.php이다. 프레임 워크를 사용하지 않고 ajax 요청을 수행하려고합니다. 사이트에서 anywheres 프레임 워크를 사용하지 않는다면 사이트로드 시간을 줄이는 것이 좋습니다. 하지만 아약스를 구현하려는 방식으로 재미있는 일들이 생겼습니다. 당신은 어떤 프레임 워크를 사용하지 않을 경우

나는 당신이

$ ('# 콘텐츠')를 언급 귀하의 코멘트에 주목 http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_callback

같은 것을 건의 할 것입니다. 부하 ('http://www.example.com/test.php ');

이것은 jQuery를 사용하여 페이지에 콘텐츠를로드하는 것을 의미합니다. 위에서 제공 한 예제 코드를 보면 실제로 jQuery를 어디서 가져 왔는지 알 수 없다. 먼저 jQuery을 가져온 다음 해당 코드를 사용해보십시오. 또한 $ ("# content") 대신 $ .ajax ({})를 사용하는 것이 좋습니다. load ("url"); 내가 PhoneGap` 당신이 휴대 전화에서 PHP를 실행할 수 있습니다`생각하지 않는다 아약스 요청 방문을 http://api.jquery.com/jQuery.ajax/

관련 문제