以下是几种常用的方法,当然取数据的后缀名可以为.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>
……