以下是使用Asp不刷新頁面取數據的3種方法,當然取數據的後綴名可以為.ASP,.JSP等等的帶參數url.
1.
<script language="JavaScript">
function loadXML(url){
var loXML = new ActiveXObject("MSXML.DOMDocument");
loXML.async = false;
loXML.load(url);
return loXML.XML;
}
</script>
<input type="button" value="loadXML方法" onClick="alert(loadXML('data.txt'))">
-- data.xml --- //數據是XML格式
<XML/>
2.
<input type="button" value="loadJS方法" onClick="loadJS('data.JS')">
<script id="getNewText"></script>
<script language="JavaScript">
function loadJS(url){
getNewText.src = url;
}
function setData(s){
alert(s)
}
</script>
-- data.js --- //數據是JS腳本賦的變量或直接執行得到結果
setData("ABC");
3.
<input type="button" value="loadFrame方法" onClick="loadFrame('data.Html')">
<script language="JavaScript">
function loadFrame(url){
document.all.getData.src = url;
}
function setData(s){
alert(s)
}
</script>
<iframe id="getData" style='display:none;'></iframe>
-- data.Html --
<script>
parent.setData("ABC")
</script>