2011-03-25 2 views
0

나는 다음과 같은 코드를 가지고 있는데, 나는 jQuery와 같은 것을 달성하려고 노력 중이다. 나는 가까이에 오는 몇 가지 해결책을 찾았지만 아직 완벽한 솔루션을 찾고 있습니다. jQuery와 AJAX로 다양한 PHP 페이지를로드하는 한 가지 기능

function getData(dataSource, divID) 
    { 
if(XMLHttpRequestObject) { 
var obj = document.getElementById(divID); 
XMLHttpRequestObject.open("GET", dataSource); 
XMLHttpRequestObject.onreadystatechange = function() 
{ 
if (XMLHttpRequestObject.readyState == 4 && 
XMLHttpRequestObject.status == 200) { 
obj.innerHTML = XMLHttpRequestObject.responseText; 
} 
} 
XMLHttpRequestObject.send(null); 
} 

} 

는 지금은 함께 기능을 트리거하고 있습니다 :

<input type = "button" value = "TEST" onclick = "getData('subject_selectAJAX.php?course_id=1', 'ajax')">

내가 jQuery로 같은 일을 달성하고 싶습니다. 나는 다음과 같은 함수가 잘못되었다고 생각하지만, 내 문제는 url이 사용자가 코스 내 어디에 있는지에 따라 바뀐다는 것입니다. course_select.php 처음에 다음 subject_select.php으로 대체 될 것 #ajax의 DIV로로드? Course_ID에 다음에 = " 무엇이든 "topic_select.php? subject_id = "어떤"

function getData() { 

    //generate the parameter for the php script 
    $.ajax({ 
     url: "something.php", //i want this to be passed to the function 
     type: "GET",   
     data: data,  
     cache: false, 
     success: function (html) { 

      //add the content retrieved from ajax and put it in the #ajax div 
      $('#ajax').html(html); 

      //display the body with fadeIn transition 
      $('#ajax').fadeIn('slow');  
     }  

}); }

저는이 부분에 대한 도움을 많이 받고 싶습니다. 현재 다른 Ajax jQuery 초보자에게 도움이 될만한 항목이라는 것을 알고 있습니다.

답변

0

이것은 훨씬 깨끗해 보이지만 느린 연결을 위해 그래픽을로드하는 일종의 것을 추가하고 싶습니다.

<script type="text/javascript"> 

function getData(url, id){ 
    $.ajax({ 
      type: "GET", 
      url: url, 
      data: "id=" + id, 
    cache: false, 
      success: function(html){ 
        $('#ajax').hide(); 

        //add the content retrieved from ajax and put it in the #content div 
        $('#ajax').html(html); 

        //display the body with fadeIn transition 
        $('#ajax').fadeIn('fast'); 



     }) 

}; 

</script>