<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<link rel="stylesheet" href="dojo/dijit/themes/claro/claro.css">
<script>dojoConfig = { parSEOnLoad: true }</script>
<script src='dojo/dojo/dojo.js'></script>
<script type="text/javascript">
function init() {
//将待传入的Web方法参数转换为json格式
var myname = dojo.toJson({ "name": "百度传课" });
//构造dojo.xhrPost方法的参数
var xhrArgs = {
//web service的地址,具体到方法名称,不能在此接参数
url: "http://localhost:21062/WebService1.asmx/Hello",
//让web service以json方式对待传入的参数
handleAs: "json",
headers: { "Content-Type": "application/json" },//或者contentType: "application/json",
//如果web方法没有参数,则下一行可不写(写了也没事儿)
// postData: myname,
load: loadHandler,
error: errorHandler
};
//以POST方式调用web service
dojo.xhrPost(xhrArgs);
}
function loadHandler(response) {
//直接取出返回的数据,如SayHello方法返回的结果:Hello yelloweast
var p = response.d;
alert("姓名:" + p.Name+",年龄:"+p.Age);
////取出返回的对象的属性,如Hello方法返回的结果:Yellow East
//alert(response.d.Name);
}
function errorHandler(error) {
alert(error);
}
dojo.addOnLoad(init);
</script>
</head>
<body>
</body>
</html>