Jump to content

Recommended Posts

I want to use XML to dynamic generate a menu using jqtouch. But it does not work.

 

My target is display same result as this static page

 

<html>

<head>

<title>Cloth Store</title>

<link type="text/css" rel="stylesheet" media="screen" href="jqtouch/jqtouch.css">

<link type="text/css" rel="stylesheet" media="screen" href="themes/jqt/theme.css">

<script type="text/javascript" src="jqtouch/jquery.1.3.2.min.js"></script>

<script type="text/javascript" src="jqtouch/jqtouch.js"></script>

<script type="text/javascript">

var jQT = new $.jQTouch();

</script>

</head>

<body>

<div id="home">

<div class="toolbar">

<h1>Cloth Store</h1>

</div>

<ul class="edgetoedge">

<li class="arrow"><a href="#books">Books</a></li>

<li class="arrow"><a href="#contactus">Contactus</a></li>

</ul>

</div>

<div id="cloth">

<div class="toolbar">

<h1>Books</h1>

<a class="button back" href="#">Back</a>

</div>

<p>We are a US-based organization providing a wide variety of books at a

reasonable price</p>

</div>

<div id="contactus">

<div class="toolbar">

<h1>Contact Us</h1>

<a class="button back" href="#">Back</a>

</div>

<p>XYZ Book Company</p>

<p>11 Books Street, NY, NY 10012 </p>

<p>USA</p>

</div>

</body>

</html>

 

I want to make the menu changed based on XML. therefore, i change the above one to 2 parts.

 

HTML:

 

<html>

<head>

<title>Cloth Store</title>

<link type="text/css" rel="stylesheet" media="screen" href="jqtouch/jqtouch.css">

<link type="text/css" rel="stylesheet" media="screen" href="themes/jqt/theme.css">

<script type="text/javascript" src="jqtouch/jquery.1.3.2.min.js"></script>

<script type="text/javascript" src="jqtouch/jqtouch.js"></script>

<script type="text/javascript">

 

var jQT = new $.jQTouch();

var xhr =new XMLHttpRequest();

xhr.open("GET","text.xml",true);

xhr.send();

var txt1=" <div class=\"toolbar\"><h1>CLC Plus</h1></div><ul class=\"edgetoedge\">";

var txt2="";

 

xhr.onreadystatechange = function(){

if(xhr.readyState == 4){

xmlDoc=xhr.responseXML;

x=xmlDoc.getElementsByTagName("name");

y=xmlDoc.getElementsByTagName("desc");

 

for (i=0;i<x.length;i++)

{

txt1=txt1 + "<li class=\"arrow\"><a href=\"#" + x.firstChild.nodeValue + "\">" + x.firstChild.nodeValue + "</a></li>";

 

txt2=txt2 + "<div id=\"" +x. firstChild.nodeValue + "</div><div class=\"toolbar\" align=right><h1>"+ x.firstChild.nodeValue+"</h1><a class=\"button back\" href=\"#\">Back</a></div><p>"+ y.firstChild.nodeValue+"</p>";

txt2 = txt2 + "</div>";

}

txt1=txt1 + "</ul>";

document.getElementById('home').innerHTML = txt1;

document.getElementById('content').innerHTML = txt2;

 

}

}

</script>

 

<body>

<div id="home" class="current">

</div>

<div id="content">

</div>

</body>

</html>

 

XML:

 

<?xml version="1.0" ?>

<company>

<name>Cloth</name><desc>We are a US-based organization providing a wide variety of books at a reasonable price</desc>

<name>Contactus</name><desc><p>XYZ Book Company</p><p>11 Books Street, NY, NY 10012 </p><p>USA</p></desc>

</company>

Link to comment
https://forums.phpfreaks.com/topic/241395-getting-jqtouch-error-when-using-xml/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.