XML : TypeError: xml is null. This is the response of my ajax call. Why?

Hy guys, I'm doing a school homework about forms, javascript and data validation, but I went further and I've created a form generator in javascript. This form generator script allows you to create a form from an xml file with specific tags, but I've noticed something wrong. This is the xml file

  <?xml version="1.0" encoding="UTF-8" ?>  <field>  <title> First Name </title>  <type> text </type>  </field>    

and this is my ajax function

  document.addEventListener("DOMContentLoaded", function() {    var request = new XMLHttpRequest ();    request.open ("GET", "formFields.xml", true);    request.send();    var xml = request.responseXML;    var fields = xml.getElementsByTagName("field");    //Other code  });    

Opening the page this script is linked to, I can see in the console of the developer tools the error "TypeError: xml is null". I've already configured my browser to open xml files in local paths. In fact, I've already resolved that error.

What makes my response null?? I've got a root element, the right encoding... What do I need else?

PS. My xml-file's name is formFields.xml, so my ajax open method is theorically ok.

No comments:

Post a Comment