woeful
دوشنبه 23 مرداد 1391, 10:55 صبح
سلام
من یه کد رو از یک کتاب آمورشی نوشتم اجرا نمیشه ۱ روزه روش گیر کردم نمیدونم مشکلش کجاست لطفا راهنمایی کنید .
<html>
<head>
<title>This is test3</title>
<script type="text/javascript">
var xmlHttp;
var requestType="";
function activeObject()
{
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
function startRequest(list)
{
requestType = list;
activeObject();
xmlHttp.onreadystatechange = handle;
xmlHttp.open("GET" , "states.xml" , true);
xmlHttp.send(null);
}
function handle()
{
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
if(requestType == "north")
{
showNorth( );
}
else if(requestType == "all")
{
showAll();
}
}
}
}
function showNorth()
{
var xmdDoc = xmlHttp.responseXML;
var northNode = xmlDoc.getElementsByTagName("north")[0];
alert("yooooooooo");
var out = "Northern States";
var northStates = northNode.getElementsByTagName("state");
outputList("Northen States",northStates);
}
function showAll()
{
var xmlDoc = cmlHttp.responseXML;
var allStates = xmlDoc.getElementsByTagName("state");
outputList("All states in Document",allStates);
}
function outputList(title , array)
{
var out = title;
var current = null;
for(var i=0;i<array.length;i++)
{
current = array[i];
out = out + "\n- " + current.childNodes[0].nodeValue;
}
alert(out);
}
</script>
</head>
<body>
<h1>Some State</h1>
<form action="#">
<input type="button" value="Click To Get Northen State" onClick="startRequest('north');"/>
<input type="button" value="Click To Get Northen State" onclick="startRequest('all');"/>
</form>
</body>
</html>
اینم فایل XML که در کد از سرور درخواست میشه
<?xml version="1.0" encoding="UTF-8"?>
<states>
<north>
<state>Minnesota</state>
<state>Iowa</state>
<state>North Dakota</state>
</north>
<south>
<state>Texas</state>
<state>Oklahoma</state>
<state>Louisiana</state>
</south>
<east>
<state>New York</state>
<state>North Carolina</state>
<state>Massachusetts</state>
</east>
<west>
<state>California</state>
<state>Oregon</state>
<state>Nevada</state>
</west>
</states>
ممنون میشم کمک کنید مشکل این کد کجاست
من یه کد رو از یک کتاب آمورشی نوشتم اجرا نمیشه ۱ روزه روش گیر کردم نمیدونم مشکلش کجاست لطفا راهنمایی کنید .
<html>
<head>
<title>This is test3</title>
<script type="text/javascript">
var xmlHttp;
var requestType="";
function activeObject()
{
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
function startRequest(list)
{
requestType = list;
activeObject();
xmlHttp.onreadystatechange = handle;
xmlHttp.open("GET" , "states.xml" , true);
xmlHttp.send(null);
}
function handle()
{
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
if(requestType == "north")
{
showNorth( );
}
else if(requestType == "all")
{
showAll();
}
}
}
}
function showNorth()
{
var xmdDoc = xmlHttp.responseXML;
var northNode = xmlDoc.getElementsByTagName("north")[0];
alert("yooooooooo");
var out = "Northern States";
var northStates = northNode.getElementsByTagName("state");
outputList("Northen States",northStates);
}
function showAll()
{
var xmlDoc = cmlHttp.responseXML;
var allStates = xmlDoc.getElementsByTagName("state");
outputList("All states in Document",allStates);
}
function outputList(title , array)
{
var out = title;
var current = null;
for(var i=0;i<array.length;i++)
{
current = array[i];
out = out + "\n- " + current.childNodes[0].nodeValue;
}
alert(out);
}
</script>
</head>
<body>
<h1>Some State</h1>
<form action="#">
<input type="button" value="Click To Get Northen State" onClick="startRequest('north');"/>
<input type="button" value="Click To Get Northen State" onclick="startRequest('all');"/>
</form>
</body>
</html>
اینم فایل XML که در کد از سرور درخواست میشه
<?xml version="1.0" encoding="UTF-8"?>
<states>
<north>
<state>Minnesota</state>
<state>Iowa</state>
<state>North Dakota</state>
</north>
<south>
<state>Texas</state>
<state>Oklahoma</state>
<state>Louisiana</state>
</south>
<east>
<state>New York</state>
<state>North Carolina</state>
<state>Massachusetts</state>
</east>
<west>
<state>California</state>
<state>Oregon</state>
<state>Nevada</state>
</west>
</states>
ممنون میشم کمک کنید مشکل این کد کجاست