-2
我正在IBM worklight中開發一個應用程序。阿賈克斯我必須連接到網站,並從中檢索數據,但它給thisd錯誤:從IBM Worklight中的服務器數據庫中檢索數據
Uncaught TypeError: Cannot call method 'getElementsByTagName' of null at file:///data/data/com.Test/files/www/default/Test.html:80
我怎樣才能解決這個問題?我的代碼是這樣的
<!DOCTYPE HTML>
<html>
<head>
<script>window.$ = window.jQuery = WLJQ;</script>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="css/Test.css">
<script>
function loadXMLDoc()
{
var xmlhttp;
var txt,x,i;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
xmlDoc=xmlhttp.responseXML;
txt="";
// x=xmlDoc.getElementsByTagName("Id");
var table = xmlDoc.getElementsByTagName("table");
var tds = table.getElementsByTagName("td");
alert(tds);
for (var i = 0; i < tds.length; i++) {
alert(tds[i].innerHTML);
}
/* for (i=0;i<x.length;i++)
{
txt=txt + x[i].childNodes[0].nodeValue + "<br>";
} */
document.getElementById("myDiv").innerHTML=txt;
}
}
xmlhttp.open("GET","http://www.marketing.com/msb_en.html",true);
xmlhttp.send();
}
</script>
</head>
<body id="content" style="display: none;">
<h2>MCollection:</h2>
<div id="myDiv"></div>
<button type="button" onclick="loadXMLDoc()">collection</button>
<!--<input type="button" value="button name" onclick="window.open('https://www.google.com.pk')" /> -->
<!--application UI goes here-->
<script src="js/initOptions.js"></script>
<script src="js/Test.js"></script>
<script src="js/messages.js"></script>
</body>
</html>
和我行80這是
var table = xmlDoc.getElementsByTagName("table");
我在HTML中沒有看到表格...因此它變爲空...? – 2013-03-14 12:13:26
是的...... PLZ建議我解決一些問題..但沒有從我給的網址獲取任何東西 – Passion 2013-03-14 12:47:30
如果HTML中沒有表格元素,你期望如何檢索它?沒有表格元素。 – 2013-03-14 12:50:10