问题描述
我想访问XMLHTT prequest.open方法我甚至包括netscape.security.PrivilegeManager.enablePrivilege(UniversalBrowserRead);
I am trying to access XMLHTTPRequest.open Method I have even included netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
但仍是其无法正常工作。
but still its not working.
我使用JavaScript和HTML访问的WebService。
I am using javascript and HTML to access the WebService.
任何帮助将是真正伟大
code
<html>
<Head>
<Title>Calling A WebService from HTML </Title>
</Head>
<Body onload='GetDataFrmWS()'>
<form name="Form1" id="Form1" runat="server" method="post">
<div id="DisplayData" > </div>
<div id="Menu2"></div>
</form>
<script language='javascript'>
var objHttp;
var objXmlDoc;
function GetDataFrmWS()
{
alert('I M Here');
var func = getDataFromWS();
}
function getDataFromWS()
{
if(window.ActiveXObject)
{
try
{
objHttp = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (ex)
{
objHttp = new ActiveXObject('Microsoft.XMLHTTP');
}
} 否则,如果(window.XMLHtt prequest) { objHttp =新window.XMLHtt prequest(); netscape.security.PrivilegeManager.enablePrivilege(UniversalBrowserRead); }
} else if (window.XMLHttpRequest) { objHttp = new window.XMLHttpRequest(); netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); }
strEnvelope ='&LT;肥皂:信封的xmlns:XSI =http://www.w3.org/2001/XMLSchema-instance的xmlns:XSD =http://www.w3.org/2001/XMLSchema XMLNS:肥皂=http://schemas.xmlsoap.org/soap/envelope/&GT; +'&LT;肥皂:身体与GT; +'&LT;的HelloWorld的xmlns =http://tempuri.org/&GT; +'&LT;虚拟的xsi:type =XSD:字符串&GT;你好&LT; /假&GT;+'&LT; / HelloWorld的&GT;+'&LT; / SOAP:身体与GT; +'&LT; /肥皂:信封&GT; ;
strEnvelope = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +'<soap:Body>' +' <HelloWorld xmlns="http://tempuri.org/">' +' <Dummy xsi:type="xsd:string">Hello</Dummy>'+' </HelloWorld>'+'</soap:Body>' +'</soap:Envelope>' ;
变种szUrl;szUrl =' HTTP://kamadhenu/Quoteme/GetCategories.asmx OP =的HelloWorld ' ;objHttp.onreadystatechange =用handleResponse;
var szUrl;szUrl = 'http://kamadhenu/Quoteme/GetCategories.asmx?op=HelloWorld';objHttp.onreadystatechange = HandleResponse;
objHttp.open(POST,szUrl,真正的);objHttp.setRequestHeader(内容类型,为text / xml');objHttp.setRequestHeader(SOAPAction报',' http://tempuri.org/HelloWorld ');objHttp.send(strEnvelope);
objHttp.open('POST', szUrl, true);objHttp.setRequestHeader('Content-Type', 'text/xml');objHttp.setRequestHeader('SOAPAction','http://tempuri.org/HelloWorld');objHttp.send(strEnvelope);
}
功能用handleResponse(){
如果(objHttp.readyState == 4) {
function HandleResponse(){
if (objHttp.readyState == 4) {
如果(window.ActiveXObject) { objXmlDoc =新的ActiveXObject(Microsoft.XMLDOM); objXmlDoc.async =假; objXmlDoc.loadXML(objHttp.responseText); VAR nodeSelect = objXmlDoc.getElementsByTagName(菜单1)项目(0)。 。VAR菜单2 = objXmlDoc.getElementsByTagName(菜单2)项目(0); 的document.getElementById('DisplayData)的innerHTML = nodeSelect.text;
的document.getElementById('菜单2)的innerHTML = Menu2.text。 } 其他 { VAR文本= objHttp.responseText; VAR分析器=新的DOMParser(); objXmlDoc = parser.parseFromString(文字,为text / xml'); 变种Value=objXmlDoc.documentElement.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].nodeValue; 变种Menu2=objXmlDoc.documentElement.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0].nodeValue; 变种Menu3=objXmlDoc.documentElement.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[1].nodeValue; 的document.getElementById('DisplayData)的innerHTML =价值;
的document.getElementById('菜单2)的innerHTML =菜单2。 的document.getElementById('菜单2)的innerHTML + =菜单3。 } }
if (window.ActiveXObject) { objXmlDoc = new ActiveXObject("Microsoft.XMLDOM"); objXmlDoc.async="false"; objXmlDoc.loadXML(objHttp.responseText); var nodeSelect = objXmlDoc.getElementsByTagName("Menu1").item(0); var Menu2=objXmlDoc.getElementsByTagName("Menu2").item(0); document.getElementById('DisplayData').innerHTML=nodeSelect.text;
document.getElementById('Menu2').innerHTML=Menu2.text; } else { var Text=objHttp.responseText; var parser=new DOMParser(); objXmlDoc = parser.parseFromString(Text,'text/xml'); var Value=objXmlDoc.documentElement.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].nodeValue; var Menu2=objXmlDoc.documentElement.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0].nodeValue; var Menu3=objXmlDoc.documentElement.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[1].nodeValue; document.getElementById('DisplayData').innerHTML=Value;
document.getElementById('Menu2').innerHTML=Menu2; document.getElementById('Menu2').innerHTML+=Menu3; } }
}
&LT; / SCRIPT&GT; &LT;输入类型=按钮文本=点击我的onclick ='GetDataFrmWS()'值=点击我!/&GT; &度;&LT; /身体&GT;&LT; / HTML&GT;
</script> <input type='Button' Text='Click Me' onclick='GetDataFrmWS()' value="Click Me!"/> °</Body></HTML>
推荐答案
我用下面的code创建一个XML对象。它已被设计来处理所有的浏览器(特别是IE和非IE)的
Browser Independent code for XML HTTPRequest
I use the following code to create an XML object. It has been designed to handle all browsers (esp. IE and non IE)
/* Function to create an XMLHTTP object for all browsers */
function getXMLHTTPObject(){
var xmlHttp;
try{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
} catch (e){
// Internet Explorer
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
alert("Your browser does not support AJAX!");
return false;
}
}
}
return xmlHttp;
}
/* End Function */
P.S。您code的问题是无法读取。请格式化
P.S. You code in the question is not readable. Pls format it
这篇关于权限被拒绝当使用XMLHtt prequest.Open跨浏览器的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!