adevine

Help with esri.request and Parsing JSON

Discussion created by adevine on Oct 15, 2012
Latest reply on Oct 17, 2012 by adevine
Morning,

I am having some trouble with esri.request and was wondering if anyone could help me. The following code is a function written by Kelly Hutchins as part of an example on displaying the HTML popup in a popup window.

function updatePopup(feature) {
         var deferred = new dojo.Deferred();
         var url = sustainBase.url + "/" + feature.attributes.layerId + "/" + feature.attributes.OBJECTID + "/htmlPopup?f=json";
         esri.request({
             url: url,
             content: url.query,
             callbackParamName: "callback",
             load: function (response) {
                 //esriServerHTMLPopupTypeAsURL
                 deferred.callback("<iframe src='" + response.content + "' frameborder='0' width='100%' height='100%' style='width: 100%; height: 100%; display: block; padding: 0px; margin: 0px;'></iframe>");

             },
             error: function (error) {
                 deferred.errback("Error occurred while generating profile");
             }
         });
         console.log(url);
         return deferred;
         return requestHandle;
     } 


It worked just fine at v2.4 of the API (when the code was written) but at 3.1, it throws an Error: NOT_FOUND_ERR: DOM Exception 8 {...} in Google Chrome. After some looking into it, I think it is because of the parsing of the callback as a "string + object +string" makes the API read it as a string when it expects an object. Problem is, I have no idea how to begin correcting that parsing to make the callback an object and have it work. I've seen suggestions on using a JSON parser or innerHtml to do this but I am at a loss on how to do so.

Could anyone take pity on a poor lad with a Friday deadline and help me with updating the parsing structure? 

Alex DeVine

Outcomes