2012-11-07 65 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

哇这个很简单..谢谢! –