Select to view content in your preferred language

Help with esri.request and Parsing JSON

1622
2
10-15-2012 04:58 AM
AlexDeVine
Occasional Contributor
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
0 Kudos
2 Replies
JeffPace
MVP Alum
in your function, you could try

var iframe = dojo.create("iframe", {
    "src": response.content,
    "style": "width: 100%; height: 100%; display: block; padding: 0px; margin: 0px;",
"frameborder":"0",
width:"100%",
height:"100%"
})
deferred.callback(iframe);

not sure on the syntax of the parameters.. but should be close
0 Kudos
AlexDeVine
Occasional Contributor
Thank you for your response, Jeff. I changed the callback into an object and that still did not work. This is whooping me. I asked KellyHutchins directly for help in another thread.

It is just baffling how this works fine in the code Kelly wrote and throws this exception in mine. I think i have done everything just like it was originally written. I guess I have not, but I have rebuilt the function scores of times and cannot figure it out.

Alex
0 Kudos