/    Sign up×
Community /Pin to ProfileBookmark

XMLhttpRequest returns responseText but not responseXML

I am trying to use the XMLhttpresponse to return the XML from the weather.com xml feed to great a google desktop gadget.

I can access the responceText property and see the XML but when I try to see the XML in the responseXML it displays nothing. Can someone help me with this? I have pasted that section of the code below for reference. Thanks, Carla

[CODE]// The current XMLHttpRequest object
var RSS_req = null;

function RSS_startRequest()
{
// Try to create new request objects until one succeeds
RSS_req = new XMLHttpRequest();
RSS_req.onreadystatechange = RSS_onReadyStateChange;

RSS_req.open(‘GET’, CONST_URLcc, true);
RSS_req.send();
}

/**
* XMLHttpRequest state change handler that passes the RSS XML document to
* the parser and continues on to the next feed.
*/
function RSS_onReadyStateChange()
{
if (RSS_req.readyState == 4)
{
// Parse the response and destroy request object
RSS_parse(RSS_req.responseText);
RSS_req = null;
}
}

function RSS_parse(responseText)
{
alert(responseText);

var xmlDoc = new ActiveXObject(“MSXML.DOMDocument”);
//var xmlDoc = new ActiveXObject(“Microsoft.XMLDOM”);
xmlDoc.async=”false”;
xmlDoc.load(responseText);

alert(xmlDoc.xml)
}
[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@holyhttpMay 11.2007 — The server response document type has to be specified as text/xml:

RSS_req.setRequestHeader('Content-Type', "text/xml");

Then you need to make sure the XML document returned is well formed.

My suggestion is to treat the XML response as Text just to see how it is formed then switch to the correct mode.

RSS_parse(RSS_req.responseXML);
Copy linkTweet thisAlerts:
@adias_angelauthorMay 11.2007 — Thanks for the response. When I add in the overridemimtype I get an error that says that object dose not support property or method..... Any ideas? I put the code below. Carla ?



[CODE]function RSS_startRequest()
{
// Try to create new request objects until one succeeds
RSS_req = new XMLHttpRequest();
RSS_req.onreadystatechange = RSS_onReadyStateChange;

RSS_req.open('GET', CONST_URLcc, true);
RSS_req.overrideMimeType('text/xml');
RSS_req.send();
}[/CODE]
×

Success!

Help @adias_angel spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...