Hi,
Can somebody help me why https://www.arcgis.com/sharing/rest/content/features/generate is returning a html instead of json response in the attached code.
getting error - Unexpected token '<'
Thanks
Chitra
we are using 3x.
I modified the code as below and getting a different error. Is my code correct?
{"error":{"code":405,"messageCode":"GWM_0005","message":"Method not supported.","details":[]}}
var layersRequest = esriRequest({ url: portalUrl + "/sharing/rest/content/features/generate", content: { 'f': "json", 'filetype': 'shapefile', 'publishParameters': JSON.stringify(params) }, handleAs: "json" }); layersRequest.then( function (response) { console.log("Success: ", response.layers); }, function (error) { console.log("Error: ", error.message); });
is this in 3x or 4x?
I thought it was 3x because you are using handleAs, but passing a query. In 3x, it's content, not query.
But if you are using 4x, it's query, but you should use responseType, not handleAs.
I have added the code through insertCode option. Thanks for letting me know.
Can someone help me why https://www.arcgis.com/sharing/rest/content/features/generate is returning a html instead of json response in the attached code.
const fileName=''; document .getElementById("uploadForm") .addEventListener("change", (event) => { fileName = event.target.value.toLowerCase(); }); //filepath is from local drive: D:\GIS\tl_2020_39_tabblock20.zip const portalUrl = "https://www.arcgis.com"; let name = fileName.split("."); name = name[0].replace("c:\\fakepath\\", ""); var params = { 'name': name, 'targetSR': this.map.spatialReference, 'maxRecordCount': 1000, 'enforceInputFileSizeLimit': true, 'enforceOutputJsonSizeLimit': true }; var extent = scaleUtils.getExtentForScale(this.map, 40000); var resolution = extent.getWidth() / this.map.width; params.generalize = true; params.maxAllowableOffset = resolution; params.reducePrecision = true; params.numberOfDigitsAfterDecimal = 0; var myContent = { 'filetype': 'shapefile', 'publishParameters': JSON.stringify(params), 'f': 'json' }; console.log(document.getElementById("uploadForm")); esriRequest({ url: portalUrl + "/sharing/rest/content/features/generate", query: myContent, form: document.getElementById("uploadForm"), handleAs: "json", load: lang.hitch(this, function (response) { if (response.error) { errorHandler(response.error); return; } var layerName = response.featureCollection.layers[0].layerDefinition.name; addShapefileToMap(response.featureCollection); }), error: lang.hitch(this, errorHandler) }); function errorHandler(error) { console.log('error!!'); } function addShapefileToMap(featureCollection) { let sourceGraphics = []; const layers = featureCollection.layers.map((layer) => { const graphics = layer.featureSet.features.map((feature) => { return Graphic.fromJSON(feature); }); sourceGraphics = sourceGraphics.concat(graphics); const featureLayer = new FeatureLayer({ objectIdField: "FID", source: graphics, fields: layer.layerDefinition.fields.map((field) => { return Field.fromJSON(field); }) }); return featureLayer; }); this.map.addMany(layers); };
Instead of providing code as an attachment, please add it using "Insert code sample". It makes it much easier to read your code and help you.
https://community.esri.com/t5/community-help-documents/how-to-insert-code-in-your-post/ta-p/914552
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.