如何使用Javascript从本地驱动器读取XML [英] How can i read XML from local drive using Javascript

查看:58
本文介绍了如何使用Javascript从本地驱动器读取XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我收到错误......参数无效



在这里我的剧本.....



< html> 
< head>< / head>
< body>

< form id =Form1method =postrunat =server>
< input type =buttononclick =MakeXMLHTTPCALL();value =Call XMLHTTP/>
< br />
< br />
< div id =MyDiv> {No result}< / div>
< / form>

< script type =text / javascript>

函数MakeXMLHTTPCALL()
{
if(window.XMLHttpRequest)
{
XmlHttpObj = new XMLHttpRequest();

}

else
{
try
{
xmlHttpObj = new ActiveXObject(Microsoft.XMLHTTP);
}
catch(e)
{
xmlHtppObj = new ActiveXObject(Msxm12.XMLHTTP);

}
}


if(XmlHttpObj)
{
XmlHttpObj.open(GET,C: \JavaScript\XMLHTTPOBJECT\DataFile.xml,TRUE); .......错误....<<<无效参数>> .....

XmlHtppObj.onreadystatechange = function()
{
if(XmlHttpObj.readyState == READYSTATE_COMPLETE)
{
document.getElementById(MyDiv)。childNode [0] .nodeValue = XmlHttpObj.responseText;
}
}
XmlHttpObj.send(null);

}

}

< / script>
< / body>
< / html>







请帮助我......



谢谢...

解决方案

尝试将以下示例中的XML URL路径替换为本地驱动器XML路径。我之前从不尝试从本地驱动器读取XML,但我认为只要提供完整路径(c:\ xml \ myxml.xml),它就应该在本地环境中工作。



用jQuery读取XML [ ^ ]



关于如何做的另一个例子



ASP.NET幻灯片控件 [ ^ ]


尝试使用ajax函数。



 


.ajax({
url:url,
data:data,
成功:成功,
dataType:dataType
});





参考此http://api.jquery.com/jQuery.get/ [ ^ ]

Hi All,

I got an error......Invalid argument

Here my script.....

<html>
<head></head>
<body>

<form id="Form1" method="post" runat="server">
<input type="button" onclick="MakeXMLHTTPCALL();"value="Call XMLHTTP"/>
<br/>
<br/>
<div id="MyDiv">{No result} </div>
</form>

<script type="text/javascript">

	function MakeXMLHTTPCALL()
	{
		if(window.XMLHttpRequest)
		{
	 	XmlHttpObj=new XMLHttpRequest();
	 
		}

		else
		{
	  	 	try
 			{
			xmlHttpObj= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
			xmlHtppObj= new ActiveXObject("Msxm12.XMLHTTP");
		
			}	
		}
	  
		
		if(XmlHttpObj)
		{
		  XmlHttpObj.open("GET","C:\JavaScript\XMLHTTPOBJECT\DataFile.xml",true);	.......ERROR....<<Invalid Argument>>.....
		
		  XmlHtppObj.onreadystatechange=function()
			{
			 if(XmlHttpObj.readyState==READYSTATE_COMPLETE)
			   {
			    document.getElementById("MyDiv").childNode[0].nodeValue=XmlHttpObj.responseText;
			   }
			}
		XmlHttpObj.send(null);
			
		}
		 
	}	

</script>
</body>
</html>




Kindly help me here....

Thanks...

解决方案

Try and replace the XML URL path in the below example with your local drive XML path. I never try reading XML from local drive before but I think it should work in your local environment as long as you provide the full path (c:\xml\myxml.xml).

Reading XML with jQuery[^]

another example on how to do it

ASP.NET Slideshow Control with jQuery and XML[^]


Try using ajax function.


.ajax({ url: url, data: data, success: success, dataType: dataType });



refer this http://api.jquery.com/jQuery.get/[^]


这篇关于如何使用Javascript从本地驱动器读取XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆