2012-11-07 62 views
2

此代碼似乎真的很長 - 但我不完全理解阿賈克斯功能是把這段代碼轉換jQuery的 - 我的主要問題是我不知道如何實現這個responseText位如何將此javascript ajax代碼轉換爲查詢ajax?

任何幫助是非常讚賞:

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

哇這個很簡單..謝謝! –