XMLHttpRequest状态未定义

时间:2015-03-25 18:51:12

标签: javascript ajax xmlhttprequest

我的代码如下所示:



function fetchgraphdata()
{
	var xmlhttp_1;

	var urls = "xml_gen_graph.jsp";
	console.log("Url Formed = " + urls);

	if (window.XMLHttpRequest) {
		xmlhttp_1 = new XMLHttpRequest();
	}
	else {
		xmlhttp_1 = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp_1.open("POST",urls, true);
	xmlhttp_1.send();
	xmlDoc = xmlhttp_1.responseXML;

	xmlhttp_1.onreadystatechange = function ()
	{
		if (xmlhttp_1.readyState === 4)
		{
			console.log("Graph data is ready");
			z = 0;
			xmlDoc = xmlhttp_1.responseXML; // xmlhttp_1.responseXML.childNodes;
			x = xmlDoc.getElementsByTagName("day");
			y = xmlDoc.getElementsByTagName("consp");
			while (xmlDoc !== null)
			{
				date_1 = x[z].childNodes[0].nodeValue;
				consp_1 = y[z].childNodes[0].nodeValue;
				console.log("date = " + date_1 + " Consumption = " + consp_1);
				z++;
			}
		}
	};

}




问题:

  1. 有时xmlhttp_1.status - > return - > undefined
  2. 有时候Uncaught TypeError: Cannot read property getElementsByTagName为null。
  3. 有时会提供正确的输出。
  4. 有人可以帮助我吗?

      

    Lorem ipsum dolor sit amet,consectetur adipiscing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua。

0 个答案:

没有答案