Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
How do you make XMLHttpRequest work on Chrome for XML files?
I have spent the past 2.5 days(day and night) creating a webpage to display information. I have finished the designing, css, and javascript all the way up to the data. Now I was thinking of using xml documents to hold the webpage data and on a click of a link, grab the string, and update the page using javascript. Only to find out through hours of research that chrome has a difficult time with ActiveX.
Strait to the point: I have found the same work around all over Google known as the 'XMLHttpRequest'. Now, the problem is that I can't seem to get it to work!
Here is my code:
function loadXmlLayout()
{
var currentXmlLayout = new XMLHttpRequest();
currentXmlLayout.open("GET", "temp.xml", false);
currentXmlLayout.onreadystatechange = srChange(currentXmlLayout);
var temp = currentXmlLayout;
alert(temp.responseXML + " : case 2"); // this will display: "null : case 2"
}
function srChange(txtFile)
{
if (txtFile.readyState === 4) { // Makes sure the document is ready to parse.
if (txtFile.status === 200) { // Makes sure it's found the file.
allText = txtFile.responseText;
lines = txtFile.responseText.split("\n"); // Will separate each line into an array
}
}
}
And here is the basic XML sample file: temp.xml
<?xml version="1.0"?>
<Food>
<drink type="soda">Root Beer</drink>
</Food>
How can I read from this xml file, grab the string "Root Beer," and then use that string?
('case 2' seems to be where everything halts :: the object is null even after opening the file)
P.S.
Google was my friend for 4-5+ hours(strait) today, now I'm looking for someone who may know the solution to this very problem...
2 Answers
- deonejuanLv 710 years agoFavorite Answer
You're right, this is an ongoing workaround. What I found after google
chrome xmlhttprequest()
was there is an extension in development. The extension supersedes security origin -- which requires careful consideration.
Are you using JSON to parse?
Look at this blog to get an idea for the browser sniffing
http://developsoftware.blogspot.com/2008/10/google...
I hope that helps. Your idea is something I have been meaning to get back to for another software project.
Source(s): http://src.chromium.org/viewvc/chrome/trunk/src/ch... ( if you click Download, then you get a blank page. Right-click to view source ) http://code.google.com/chrome/extensions/xhr.html