2012-03-13 7 views
0

이 문제는 나를 미치게 만듭니다. 저는 PHP 파일을 Ajax를 통해 호출하고 HTML 컨텐츠로 파싱합니다. 페이지를 새로 고치지 않고도 동적 콘텐츠를 유지하려면 그렇게해야합니다.JQuery가 구문 분석 된 컨텐츠와 함께 작동하지 않습니다.

내 문제는 구문 분석 된 코드가 jquery 물건을 실행하지 않는다는 것입니다. 예를 들어 PHP 파일에서 Jquery 슬라이더가 필요합니다. 하지만 정상적인 HTML로 구문 분석되고 JQuery는 인식하지 못합니다.

HTML 파일 :

<html> 
    <head> 
     <script src="jquery-1.7.1" type="text/javascript"></script> 
     <script src="jscroller-0.4.js" type="text/javascript"></script> 

     <script type="text/javascript"> 
      $(document).ready(function() 
      { 
       // Add Scroller Object 
       $jScroller.add("#scroller_container","#scroller","right",1); 
       // Start Autoscroller 
       $jScroller.start(); 
      }); 
     </script> 


     <script type="text/javascript"> 
      function showGet(str) 
      { 
       if (str=="") 
       { 
       document.getElementById("center").innerHTML=""; 
       return; 
      } 

      if (window.XMLHttpRequest) 
      {// code for IE7+, Firefox, Chrome, Opera, Safari 
       xmlhttp=new XMLHttpRequest(); 
      } 
      else 
      {// code for IE6, IE5 
       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
      } 

      xmlhttp.onreadystatechange=function() 
      { 
       if (xmlhttp.readyState==4 && xmlhttp.status==200) 
       { 
        document.getElementById("content").innerHTML=xmlhttp.responseText; 
       } 
      } 

      xmlhttp.open("GET","content.php?q="+str,true); 
      xmlhttp.send(); 
      } 
     </script> 
    </head> 

    <body> 
     <div id="content"> 
      <input type="button" onclick="showGet(1)" value="showGet"> 
     </div> 

     <div id="scroller_container"> 
     <div id="scroller"> 
      ...[Content]... 
     </div> 
     </div> 
    </body> 
</html> 

가 여기에 content.PHP 파일입니다 :

<?php 

    echo " 
     <div id=\"scroller_container\"> 
      <div id=\"scroller\"> 
       ...[Content]... 
      </div> 
     </div> 
     " 

?> 

처형의 HTML에 버튼이

다음은 샘플입니다. 버튼을 클릭하면 content.php가 <div id="content></div>으로 파싱됩니다. PHP에 HTML과 동일한 <div id="scroller" ....이 포함되어 있습니다.

HTML div가 작동하지만 PHP 파일에있는 HTML div는 작동하지 않습니다. 왜???? 어떻게 작동시킬 수 있습니까?

모든 힌트를 미리 알려주고 있습니다. 사용

http://api.jquery.com/on/ http://api.jquery.com/delegate/

+2

이 왜 jQuery의 사용하지 않는 Ajax는 기능을합니까? 그들은 구현하기가 훨씬 쉽습니다. 게다가 Ajax 결과의 스크립트를 실행하고 있습니다. –

+0

나는 원하는 지식을 놓치고 싶습니다. 나에게 쉬운 모범이 있습니까? –

+1

설명서에 몇 가지 예가 있습니다. http://api.jquery.com/jQuery.ajax/ –

답변

1

콘텐츠로드 -

+0

Wonderfull! 그 일을 했어. 샤 우드가 너희들에게 먼저 물어 보았다. 너무 많은 시간 낭비 .... 정말 고마워요! –

0

jQuery를 기능에 동적으로 추가 정보 액세스를 얻으려면 당신은에 위임() 또는()를 사용해야합니다 jQuery를 아약스는 간단 할 수있는 부하를 사용하여 다음() 메소드와 같은 :

http://api.jquery.com/load/

/* loads a file into id=content and replaces exisitng html*/ 
$('#content').load('path/to/server/file', function(){ 
    /* new content exists, intialize event handling 
    and plugins for new html here*/ 


}) 
관련 문제