/    Sign up×
Community /Pin to ProfileBookmark

Loading a file with javascipt

Hey ! I’m currently playing a little bit with javascript. Currently I’m working through a tutorial on the web ( [url]http://www.w3schools.com/dom/dom_nodes_navigate.asp[/url] ). They show some examples and I try to reprogramm these.

So I have this webpage:

[code=html]<html>
<head>
<script type=”text/javascript” language=”JavaScript” src=”script.js”></script>
</head>

<body>
<form id=”_id0″ method=”post” action=”/XML_DOM/index.jsf” enctype=”application/x-www-form-urlencoded”>

<input type=”submit” name=”_id0:_id1″ value=”start js” onclick=”testXML(‘mydiv’);” />
<input type=”hidden” name=”_id0″ value=”_id0″ /></form>
<div id=”mydiv”></div>
</body>

</html>[/code]

This is the script.js

[CODE]function testXML( id ) {
var xmlDoc;
//Safari?
if( document.implementation && document.implementation.createDocument ) {
xmlDoc = document.implementation.createDocument(“”,””,null);
//IE
} else {
xmlDoc = new ActiveXObject(“Microsoft.XMLDOM”);
}
xmlDoc.async = false;

var mydiv = document.getElementById(id);
mydiv.innerText = mydiv.innerText + “Loaded until here”;
xmlDoc.loadXML(“/XML_DOM/books.xml”);
mydiv.innerText = ” loaded sucessfully!!!”;
}[/CODE]

and the xml file books.xml

[CODE]<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<!– Edited with XML Spy v2007 (http://www.altova.com) –>
<bookstore>
<book category=”COOKING”>
<title lang=”en”>Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category=”CHILDREN”>
<title lang=”en”>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category=”WEB”>
<title lang=”en”>XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category=”WEB”>
<title lang=”en”>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>[/CODE]

All files are in the same directory ( “/XML_DOM/” ). But the book.xml is not loaded. Why?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @toom 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,
)...