adevine

Kelly Hutchins: Please Help With Esri.Request Issue!

Discussion created by adevine on Oct 17, 2012
Latest reply on Oct 19, 2012 by adevine
Kelly,

I have been trying to adapt your updatePopup solution for displaying HTML popups in a popup window and cannot get it to work.  This is your original code:

function updatePopup(graphic){
      var deferred = new dojo.Deferred();
      var url = graphic.getLayer().url + "/" + graphic.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");
      }
      });
      return deferred;
     
      return requestHandle;
 
  }


I am reading your code thusly: Make a new deferred object. Construct a new url to the access the REST location of the esriServerHTMLPopupTypeAsURL. make esri.request defining the callback of the deferred object as the HTML for displaying the esriServerHTMLPopupTypeAsURL content in an iframe and hand it to the popup window. It works when I run it. It uses the 2.4 JSAPI.

Now, I think I am doing the same thing. My code: 

       function updatePopup(feature) {
          var deferred = new dojo.Deferred();
          var url_string = sustainBase.url + "/" + feature.attributes.layerId + "/" + feature.attributes.OBJECTID + "/htmlPopup?f=json";
            
          esri.request({
                url: url_string,
                content: url_string.query,
                callbackParamName: "callback",
                load: function (response) {
                    //esriServerHTMLPopupTypeAsURL                    
                    deferred.callback(response.content);
                },
                error: function (error) {
                    deferred.errback("Error occurred while generating profile");
                }
          });
          return deferred;
          return requestHandle;

        }


(Using JSAPI 2.8) I am making a new deferred object. I am construct a new url to the access the REST location of the esriServerHTMLPopupTypeAsURL. I am making an esri.request defining the callback of the deferred object as the HTML for displaying the esriServerHTMLPopupTypeAsURL content in an iframe (I defined my esriServerHTMLPopupTypeAsURL as the entire iframe HTML so I can just use response.content). and hand it to the popup window. It does not work. The function breaks when it hits "return deferred". 

Exception... "Could not convert JavaScript argument arg 0 [nsIDOMHTMLDivElement.appendChild]"  nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)"  location: "JS frame :: http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.8 :: <TOP_LEVEL> :: line 14"  data: no] 


I have tried using the 2.4 JSAPI which didn't work. I have tried using console.log to verify that my esri.request is working and returning the correct string, and it is. Also, after researching the error, i tried using DOMParser to convert the response.content string to a DOM and that didn't work either. The error Firebug is returning indicates a type mismatch error but I cannot figure it out.

Any help or insight into this that you could provide would be very much appreciated.

Alex

Outcomes