|
本人做了个通过js读取xml数据的小程序,单独执行html文件是可以的,但放到phonegap下就取不到,能谈出"kkkk",但弹不出"kkkk1"。test.XML与index.html在同一目录下。代码如下,求高手解答。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="xml/text; charset=utf-8" />
<title>honeGap</title>
<script type="text/javascript" charset="utf-8" src="js/phonegap.js"></script>
<script type="text/javascript" src="js/jquery-1.2.6.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var content="<tr bgcolor=\"#FFCC33\"><td height=\"32\">ID</td><td>Name</td><td>Age</td><td>QQ</td><td>Email</td></tr>";
$.ajax({
type:"GET",
url:"test.XML",
error: function(xml) { alert("加载XML 文件出错!"); },
success:function(userinfo){
alert("kkkk");
$(userinfo).find('userInfo').each(function(){
alert("kkkk1");
var id=$(this).attr('id');
var name= $(this).find('userName').text();
var age= $(this).find('age').text();
var qq= $(this).find('QQ').text();
var email= $(this).find('Email').text();
alert(name);
content+="<tr><td height=\"32\">"+id+"</td><td>"+name+"</td><td>"+age+"</td><td>"+qq+"</td><td>"+email+"</td></tr>";
});
document.write("<table border=\"1\" cellpadding=\"0\">"+content+"</table>");
}
});
});
</script>
</head>
<body>
</body>
</html>
<?xml version="1.0" encoding="utf-8" ?>
<xml>
<userInfo id="888888" imageurl="http://www.iwms.net/buy/pic/product_6.gif">
<userName>
apple
</userName>
<age>
25
</age>
<QQ>
666666
</QQ>
<Email>
apple@eee.com
</Email>
</userInfo>
</xml>
|
|