You can use a Feature Layer if you're using a 2.x version of the API. Here's a simple page that uses the 2.3 version of the API and a feature layer based on a 9.31 ArcGIS Server instance:<!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" />
<!--The viewport meta tag is used to improve the presentation and behavior of the samples
on iOS devices-->
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>FeatureLayer On Demand</title>
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.3/js/dojo/dijit/themes/claro/claro.css">
<style>
html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
</style>
<script type="text/javascript">djConfig = { parseOnLoad:true };</script>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.3"></script>
<script type="text/javascript">
dojo.require("esri.map");
dojo.require("esri.layers.FeatureLayer");
var map;
function init() {
var extent = new esri.geometry.Extent({"xmin":-1091160.6279576253,"ymin":1464985.3783563056,"xmax":767849.8897356443,"ymax":2365380.130188807,"spatialReference":{"wkid":102039}});
map = new esri.Map("map", { extent: extent });
dojo.connect(map, "onLoad", initOperationalLayer);
var base = new esri.layers.ArcGISDynamicMapServiceLayer("http://gis.apfo.usda.gov/ArcGIS/rest/services/CONUS/Overview/MapServer");
map.addLayer(base);
}
function initOperationalLayer(map) {
var content = "<b>Abbr</b>: ${STATE_ABBR}<br /><b>FIPS</b>: ${STATE_FIPS}";
var infoTemplate = new esri.InfoTemplate("${STATE_NAME}", content);
var featureLayer = new esri.layers.FeatureLayer("http://gis.apfo.usda.gov/ArcGIS/rest/services/CONUS/Overview/MapServer/1",{
mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
outFields: ["*"],
infoTemplate: infoTemplate
});
// explicitly set OID field as the layer being used
// does not have it's OID field visible
featureLayer.objectIdField = 'STATE_FIPS';
map.addLayer(featureLayer);
map.infoWindow.resize(150,105);
}
dojo.ready(init);
</script>
</head>
<body class="claro">
<div style="position:relative;width:100%;height:100%;">
<div id="map" style="border:1px solid #000;width:100%;height:100%;">
</div>
</body>
</html>
To use esri.request(), you would make a request to your map service layer endpoint and pull the info you need out of the fields array, here's an example:// use esri.request to get field info
esri.request({
url: 'http://gis.apfo.usda.gov/ArcGIS/rest/services/CONUS/Overview/MapServer/1',
content: { f: 'json' },
callbackParamName: 'callback',
load: function(resp) {
dojo.forEach(resp.fields, function(field) {
console.log('field name is ', field.name, ' and field alias is ', field.alias);
});
},
error: function(err) { console.log('err: ', err); }
});