2014-02-14 48 views
0

我正在使用这个AJAX代码来加载一个PHP页面来更改一个MySQL子句的ORDER BY。 另外我有一个叫getDESC的功能。AJAX:获取两个文档

现在我想扩展这两个代码,得到两个PHP文档。这些是与kate.php的katbox。这是可能的,你能帮忙写这段代码吗?

function getASC() 
{ 
    xmlHttp = CreateXmlHttpObjet(); 

    if (xmlHttp == null) 
     return; 

    xmlHttp.onreadystatechange = function() { 
     document.getElementById('ascbox').innerHTML = xmlHttp.responseText; 
    }; 

    xmlHttp.open('GET', 'asc.php', true); 
    xmlHttp.send(null); 
} 
+0

ehrm ...只执行了两次,另一个目标文件? – giorgio

+1

为什么不直接在'asc.php'中使用include? –

+0

我在我的sql代码中有两个变量,我想用两个按钮切换每个变量。这些按钮正在启动ajax函数 – donbenni

回答

0

只需更新功能像这样,现在你可以打电话getAJAX('ascbox', 'asc.php')getAJAX('katbox', 'kate.php')

function getAJAX(id, php) 
{ 
    xmlHttp = CreateXmlHttpObjet(); 

    if (xmlHttp == null) 
     return; 

    xmlHttp.onreadystatechange = function() { 
     document.getElementById(id).innerHTML = xmlHttp.responseText; 
    }; 

    xmlHttp.open('GET', php, true); 
    xmlHttp.send(null); 
}