<html>
<head>
<title>test</title>
<script type="text/javascript"
src="js/dojo/dojo/dojo.js"
djConfig="parseOnLoad: true"></script>
<script type="text/javascript">
var xhrArgs = {
url:"http://localhost:8080/dojoSample/hello.html",
handleAs:"text",
load:function(responseText)
{
alert(responseText);
dojo.byId("divHello").innerHTML = responseText;
},
error:function(response)
{
alert("Error");
}
};
function sayHello(){
dojo.xhrGet(xhrArgs);
}
</script>
</head>
<body>
<div id="divHello"></div>
<button id="btn" type="button" onclick="sayHello()">sayHello</button>
</body>
</html>
上面的代码等将于
<html>
<head>
<title>test</title>
<script type="text/javascript"
src="js/dojo/dojo/dojo.js"
djConfig="parseOnLoad: true"></script>
<script type="text/javascript">
function sayHello(){
dojo.xhrGet({
url:"http://localhost:8080dojoSample/hello.html",
handleAs:"text",
load:function(responseText)
{
alert(responseText);
dojo.byId("divHello").innerHTML = responseText;
},
error:function(response)
{
alert("Error");
}
});
}
</script>
</head>
<body>
<div id="divHello"></div>
<button id="btn" type="button" onclick="sayHello()">sayHello</button>
</body>
</html>
输出结果:
Hello,World!
hello.html代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hello</title>
</head>
<body>
Hello,World!
</body>
</html>