Opened 10 years ago

Closed 10 years ago

#15273 closed defect (invalid)

dojo/request and handleAs: "xml" not working

Reported by: Kitson Kelly Owned by: Bryan Forbes
Priority: undecided Milestone: tbd
Component: Core Version: 1.7.2
Keywords: Cc:
Blocked By: Blocking:


I am geting an empty object (e.g. {}) when doing the following with dojo/request:

I have the following file as helloworld.xml:

<?xml version="1.0" encoding="UTF-8" ?>

And I do the following:

require(["dojo/request"], function(request){
  request("helloworld.xml", function(response){

Change History (4)

comment:1 Changed 10 years ago by Bryan Forbes

Owner: set to Bryan Forbes
Status: newassigned

comment:2 Changed 10 years ago by Bryan Forbes

Resolution: invalid
Status: assignedclosed

This isn't a bug. A couple of comments on this snippet:

  • The second argument to request is an object, not a function. You should be chaining a then() call off the return.
  • You're not passing { handleAs: "xml" } to request(), so it handles the return as text.

comment:3 Changed 10 years ago by Kitson Kelly

Resolution: invalid
Status: closedreopened

Sorry, I was typing my example example wrong. I should have copied and pasted the code that I put in the documentation, instead of just typing stuff off the top of my head. Apologies...

This is what I had in the reference-guide as an example:

require(["dojo/request", "dojo/dom", "dojo/dom-construct", "dojo/json", "dojo/on", "dojo/domReady!"],
function(request, dom, domConst, JSON, on){
  on(dom.byId("startButton"), "click", function(){"<p>Requesting...</p>", "output");
      handleAs: "xml"
    }).then(function(response){"<p> <code>" + JSON.stringify( + "</code>", "output");
<div id="output"></div>
<button type="button" id="startButton">Start</button>

comment:4 Changed 10 years ago by Bryan Forbes

Resolution: invalid
Status: reopenedclosed

The problem is that is not valid XML so the browser fails to parse it. Change the XML to something like the following and will be populated:

<?xml version="1.0" encoding="UTF-8"?>
<div id="output"></div>
<button type="button" id="startButton">Start</button>
Note: See TracTickets for help on using tickets.