Unexpected token <(…) For Feature Attachment

4763
4
11-28-2016 01:23 AM
PrasadG
New Contributor II

Got Error  "Unexpected token <(…)" For Feature Attachment it is problem with my init.js.  If i used  <script src="https://js.arcgis.com/3.18/"></script> i got correct  result.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

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

<link rel="stylesheet" href="http://XXXXX/arcgis_js_api/library/3.17/3.17/esri/css/esri.css">
<style>
html, body { height: 100%; width: 100%; margin: 0; overflow: hidden; }
#map { height: 100%; padding: 0;}
#footer { height: 2em; text-align: center; font-size: 1.1em; padding: 0.5em; }
.dj_ie .infowindow .window .top .right .user .content { position: relative; }
.dj_ie .simpleInfoWindow .content {position: relative;}
</style>

<script src="http://XXXX/arcgis_js_api/library/3.17/3.17/init.js"></script>
<script>
var map;

require([
"esri/map",
"esri/layers/FeatureLayer",
"esri/dijit/editing/AttachmentEditor",

"dojo/parser", "dojo/dom",

"dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"
], function(
Map, FeatureLayer, AttachmentEditor,
parser, dom
) {
parser.parse();

map = new Map("map", {
basemap: "gray",
center: [80,18],
zoom: 8
});
map.on("load", mapLoaded);

function mapLoaded() {
var featureLayer = new FeatureLayer("http://XXXXXXX/Attachments/FeatureServer/0",{
mode: FeatureLayer.MODE_ONDEMAND
});

map.infoWindow.setContent("<div id='content' style='width:100%'></div>");
map.infoWindow.resize(350,200);
var attachmentEditor = new AttachmentEditor({}, dom.byId("content"));
attachmentEditor.startup();

featureLayer.on("click", function(evt) {
var objectId = evt.graphic.attributes[featureLayer.objectIdField];
map.infoWindow.setTitle(objectId);
attachmentEditor.showAttachments(evt.graphic,featureLayer);
map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));
});
map.addLayer(featureLayer);
}
});
</script>
</head>

<body>
<div data-dojo-type="dijit/layout/BorderContainer"
data-dojo-props="design:'headline'"
style="width:100%;height:100%;">

<div id="map"
data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'center'"></div>

<div id="footer"
data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'bottom'">
Click point to view/create/delete attachments.
</div>
</div>
</body>
</html>

Tags (1)
0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Prasad,

   When I switched the code to use the CDN urls for the esri JS API instead of your local install. The code worked fine. 

thejuskambi
Occasional Contributor III

You usually get this error when a html response is returned when, a json response is expected. Check the request and response in the Network tab and see if it gives a clue what's going wrong.

PrasadG
New Contributor II

hi thejus i checked but can't understand  network related problems ....is their any simple solution...?

0 Kudos
thejuskambi
Occasional Contributor III

Prasad,

I cannot give you a solution, without knowing what the problem is.

All I am saying is the "Unexpected token < ..." error occurs when the server returns html instead or JSON. The "<" is not a valid in JSON, but it is used in HTML to begin a tag. The html can be anything from 'server not found' 404 or 'service unavailable' 503 etc.

You need to open the browser's developer window and look through all the requests sent, as well as response received. See if it contains any HTML response out of the ordinary. That will give is a clue what might be the cause of the problem.

Hope this was helpful.

0 Kudos