2012-11-07 5 views
2

이 코드는 정말 긴 것 같다 -하지만 난이 코드를 변환하는 기능 아약스 JQuery와 이해를 완벽하게 해달라고 - 내 주요 문제는 내가에서 responseText 비트 어떤 도움이 아주 많이 감사합니다이 자바 스크립트 아약스 코드를 어떻게 쿼리 아약스로 변환합니까?

구현하는 방법을 잘 모릅니다입니다 :

function getCategory(category){ 
    if (window.XMLHttpRequest){ 
    xmlhttp=new XMLHttpRequest(); 
    }else{ 
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    xmlhttp.onreadystatechange=function(){ 
    if (xmlhttp.readyState==4 && xmlhttp.status==200){ 
     document.getElementById("products").innerHTML=xmlhttp.responseText; 
    } 
    } 
    xmlhttp.open("GET","productlist.php?q="+category,true); 
    xmlhttp.send(); 
} 

답변

3
$.ajax({ 
    url: "productlist.php?q=" + category, 
    success: function(data) { 
     $("#products").html(data); 
    } 
}); 

또는 단순히 :

$("#products").load("productlist.php?q=" + category); 

그리고 함수 랩 원인

:

function getCategory(category) { 
    $("#products").load("productlist.php?q=" + category); 
} 
+0

간단한 ... 감사합니다! –

관련 문제