0

I am trying to import a XML-file into a HTML document with Javascript.

It works fine for Firefox, but it doesn't work for IE-10 and Chrome.

My script:

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET","xml_input.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

I think they changed the XMLHttpRequest again but I can't find it's replacement anywhere. I'm hoping someone on this site can help me.

2 Answers 2

2

Are you using a server of some kind? If you're testing off of a local address, e.g. file://whatever/your/thing/is you won't be able to make any HTTP requests by default unless you're in Firefox or Safari.

If you are using a server, do you get any errors in your console? Can you see the request being attempted in the network tab?

Sign up to request clarification or add additional context in comments.

Comments

1

How about importing jquery into your project and using its wonderful $.ajax function. It will figure out the stuff under the covers (XMLHTTP) and you won't have to worry about this anymore. You want this to be abstracted away!.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.