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: |
Description
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" ?> <hello>world</hello>
And I do the following:
require(["dojo/request"], function(request){ request("helloworld.xml", function(response){ console.log(response.data); }); });
Change History (4)
comment:1 Changed 10 years ago by
Owner: | set to Bryan Forbes |
---|---|
Status: | new → assigned |
comment:2 Changed 10 years ago by
Resolution: | → invalid |
---|---|
Status: | assigned → closed |
comment:3 Changed 10 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
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(){ domConst.place("<p>Requesting...</p>", "output"); request("./helloworld.xml",{ handleAs: "xml" }).then(function(response){ domConst.place("<p>response.data: <code>" + JSON.stringify(response.data) + "</code>", "output"); }); }); });
<h1>Output:</h1> <div id="output"></div> <button type="button" id="startButton">Start</button>
comment:4 Changed 10 years ago by
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
The problem is that is not valid XML so the browser fails to parse it. Change the XML to something like the following and response.data
will be populated:
<?xml version="1.0" encoding="UTF-8"?> <root> <h1>Output:</h1> <div id="output"></div> <button type="button" id="startButton">Start</button> </root>
Note: See
TracTickets for help on using
tickets.
This isn't a bug. A couple of comments on this snippet:
then()
call off the return.
{ handleAs: "xml" }
to
request()
, so it handles the return as text.