javascript调用rest地址,获取页面值

0
分享 2012-06-28
在用ArcGIS Server JavaScript开发中,经常遇到和其它平台对接或者调用SOE时,需要用js访问rest页面获得页面值,下面示例代码:
(注:此处是一个非常简单的示例,根据arcgis server页面的query操作,设置where="1=1"后构造的url,然后获取要素的示例)
<!DOCTYPE html> 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">

<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>JSON Content</title>



<script>var dojoConfig = { isDebug: true };</script>
<script src="http://serverapi.arcgisonline. ... gt%3B
<script>

var url = "http://localhost:6080/arcgis/r ... 3B%3B
var xmlHttp=GetXmlHttpObject();
function getContent()
{
xmlHttp.open("GET",url,true); //submit the URL request
xmlHttp.send(null);
xmlHttp.onreadystatechange= function()
{
// Here we process the response
var responseText=xmlHttp.responseText;
alert(responseText);

}
}


function GetXmlHttpObject() {
var xmlHttp=null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
} catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
if (xmlHttp==null) {
alert ("Your browser does not support AJAX!");
return;
}
return xmlHttp;
}

</script>
</head>

<body style="font-family: Arial Unicode MS,Arial,sans-serif;">

<p>
Enter URL here: <input type="text" disabled="true" id="url" size="75" />
<input type="button" value="GO" onclick="getContent();" />
<span id="status"></span>
</p>
<p>

</body>
</html>



运行后执行,弹出结果窗体(以json格式返回前台)

文章来源:http://www.cnblogs.com/esrichina/archive/2013/05/24/3096938.html

0 个评论

要回复文章请先登录注册