xml not retrived by javascript -


this may seem trivial have tried possible methods

  1. async=true (onreadystatechange)
  2. async=false (xmlhttp open)

source http://www.w3schools.com/dom/dom_httprequest.asp

3.xmlhttp.open("get","http://"+location.host+"/cd_catalog.xml",false)

source

open xml , display data in div

basically want javascript , xml in same folder , use javascript return values.

the actual program working on:

var xmlsolver = function makexmlsolver(){}; xmlsolver.getallauthorsinstock()=function() { var author=xmldoc.getelementsbytagname        ("author").childnodes.nodevalue;  return author;  };     xmlsolver.getallbooksinstock()=function()    { var title=xmldoc.getelementsbytagname      ("title").childnodes.nodevalue;      } 

and xml

<?xml version='1.0'?>  <!-- file represents fragment of book store inventory database -->  <bookcollection>    <book genre="philosophy" publicationdate="1991" isbn="1-861001-57-6">      <title>the gorgias</title>      <author>        <name>plato</name>      </author>      <price>9.99</price>    </book>    <book genre="autobiography" publicationdate="1981" isbn="1-861003-11-0">      <title>the autobiography of benjamin franklin</title>      <author>        <firstname>benjamin</firstname>        <lastname>franklin</lastname>      </author>      <price>8.99</price>    </book>    <book genre="novel" publicationdate="1967" isbn="0-201-63361-2">      <title>the confidence man</title>      <author>        <firstname>herman</firstname>        <lastname>melville</lastname>      </author>      <price>11.99</price>    </book>    <book genre="novel" publicationdate="2002" isbn="0-201-63361-2">      <title>oryx , crake</title>      <author>        <firstname>margaret</firstname>        <lastname>atwood</lastname>      </author>      <price>11.99</price>    </book>    <book genre="philosophy" publicationdate="1991" isbn="1-861001-57-6">      <title>the republic</title>      <author>        <name>plato</name>      </author>      <price>7.99</price>    </book>  </bookcollection>

sounds cors issue me. safety mechanism built browsers prevents javascript reading local files.

one possible workaround (for chrome browser @ least) install , enable allow-control-allow-origin plugin.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -