本文介绍了权限被拒绝错误 XMLHttpRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><头><title>使用 XmlHttpRequest 调用 Web 服务</title><script type="text/javascript" language="javascript">var xmlhttp;var XMLContent='<XML ID="Transaction"><Transaction>'+''+'<Email>artur</Email>'+''+'</登录详情>'+''+'<JobId>40170978</JobId>'+'<JobRefNo>prod84</JobRefNo>'+'<职位名称>'+'<![CDATA[研发软件产品总监(多媒体)]]>'+'</职位名称>'+'<JobExpiry>30</JobExpiry>'+''+'<![CDATA[布赖恩麦克法登]]>'+'</JobContactName>'+'<JobContactEmail>[email protected]</JobContactEmail>'+'<JobShortDesc>'+'<![CDATA[研发软件产品概念多媒体 Web 2.0 总监]]>'+'</JobShortDesc>'+'<JobDetDesc<<![CDATA[ <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"<STRONG>软件产品概念研发总监</STRONG> 从头开始建立一个新的原型团队和流程,利用敏捷开发模型,管理研发团队制定一个强大的愿景,并能够清楚地阐明团队将在方法论和工具方面采取的方向J2EE、.NET、Flash、AJAX、DHTML、JavaScript等技术,从首席研究员那里获取营销需求并编写功能需求文档,管理研发预算,管理内部团队和供应商开发的项目.</P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto">要获得这个新角色,您将拥有 IT 学位/拥有超过 5 年的软件和超过 5 年的研发/原型开发前沿开发经验,并在软件生产/产品环境、项目管理和流程管理技能 (AGILE) 中领先前沿开发团队,并展示了在产品创新和发布方面的工作经验.您可能从事教育游戏、社交网络、Web 2.0 应用程序、移动技术、学习管理系统、在线课件或共享软件的工作.</P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"></P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">套餐为€105K + Bonus + VHI + Pension + 搬迁套餐(如适用)+股票期权可以协商.有很好的职业发展机会.要讨论这个和其他机会,请将最新简历发送至 <A href="mailto:[email protected]">[email protected]</A>或拨打 +353 1 6489113 保密.未经您的同意,您的详细信息不会发送给任何第三方.</P><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"> </P>]]>'+'</JobDetDesc>'+'<JobSalary>90000</JobSalary>'+'<JobSalaryMax>105000</JobSalaryMax>'+''+'</JobQues1>'+''+'</JobQues2>'+''+'</JobQues3>'+''+'<JobAddnlBens>17,14,23,1,5,9,12,10</JobAddnlBens>'+'<工作地点>96,98,97</工作地点>'+'<JobEducations>8</JobEducations>'+'<工作经历>10</工作经历>'+'<工作类别>1043,1050</工作类别>'+'<JobSubcategories>69896,69869</JobSubcategories>'+'</工作详情>'+'</交易>'+'</XML>';函数 on_click(){如果(窗口.ActiveXObject){尝试{xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');}抓住(前){xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');}}否则如果(window.XMLHttpRequest){xmlhttp = 新窗口.XMLHttpRequest();netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");}var xmlToSend = '<?xml version="1.0" encoding="utf-8"?>'+'<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/">'+'<肥皂:身体>'+'<InsertXML xmlns="http://recpushdata.cyndigo.com/">'+'<工作>'+XMLContent+'</工作>'+'</InsertXML>'+'</肥皂:身体>'+'</soap:信封>';var szUrl;szUrl = 'http://recpushdata.cyndigo.com/Jobs.asmx?op=InsertXML';xmlhttp.onreadystatechange = state_Change;xmlhttp.open("发布", szUrl, true);xmlhttp.setRequestHeader ("SOAPAction", "http://recpushdata.cyndigo.com/InsertXML");xmlhttp.setRequestHeader("Content-Type", "text/xml");xmlhttp.send(xmlToSend);}函数 state_Change(){//如果 xmlhttp 显示已加载"如果(xmlhttp.readyState==4){//如果正常"如果(xmlhttp.status==200){alert("OK"+xmlhttp.responseText);}别的{alert("获取 XML 数据的问题"+xmlhttp.responseText);}}}<身体><div><h1>单击按钮调用 Web 服务<input type="button" onclick="return on_click();"值=确定"/>

<div id="responseDiv">

</html>

解决方案

XmlHttpRequest 只能用于从提供页面的域/服务器调用本地服务.

因此,如果您提供的网页来自:

http://www.example.com/page1

您不能将 XmlHttpRequest 发送到:

http://www.sample.com/webservice
  
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Calling a Web Service Using XmlHttpRequest</title>

    <script type="text/javascript" language="javascript">

var xmlhttp;


var XMLContent='<XML ID="Transaction"><Transaction>'+
'<LoginDetails>'+
'<Email>artur</Email>'+
'<Password>demos2</Password>'+
'</LoginDetails>'+
'<JobDetails>'+
'<JobId>40170978</JobId>'+
'<JobRefNo>prod84</JobRefNo>'+
'<JobTitle>'+
'<![CDATA[ Director of R&D Software product  (Multimedia)]]>'+
'</JobTitle>'+
'<JobExpiry>30</JobExpiry>'+
'<JobContactName>'+
'<![CDATA[ Brian Mc Fadden]]>'+
'</JobContactName>'+
'<JobContactEmail>[email protected]</JobContactEmail>'+
'<JobShortDesc>'+
'<![CDATA[ Director of R&D Software product concepts Multimedia Web 2.0]]> '+
'</JobShortDesc>'+
'<JobDetDesc><![CDATA[ <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><STRONG>Director of R&D Software product concepts to</STRONG>  build a the new prototyping team and processes from the ground up, utilizing an agile development model, manage the R&D team develop a strong vision and be able to clearly articulate the direction the group will take in terms of methodologies and tools in technologies such as J2EE, .NET, Flash, AJAX, DHTML, JavaScript, take marketing requirements from the principal investigators and write functional requirement documents, manage budget for R&D development,  manage the projects developed by the internal team and vendors. </P>  <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto">To get this new role you will have a degree in IT / Software and over 5 years plus doing cutting edge development in R&D/ prototyping and leading cutting edge development teams in a software production / product environment, project management and process management skills (AGILE) and demonstrated experience working on product innovation and releases. You may be working in educational gaming, social networking, Web 2.0 applications, mobile technologies, learning management systems, online courseware or shareware. </P>  <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"> </P>  <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">The package is to €105K + Bonus + VHI + Pension + relocation package where applicable + stock options may be negotiated. There are great career advancement opportunities. To discuss this and other opportunities please send an up-to-date resume to <A href="mailto:[email protected]">[email protected]</A> or call +353 1 6489113 in confidence. Your details will not be sent to any third party without your consent. </P>  <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"> </P>]]>'+
'</JobDetDesc>'+
'<JobSalary>90000</JobSalary>'+
'<JobSalaryMax>105000</JobSalaryMax>'+
'<JobQues1><![CDATA[ ]]>'+
'</JobQues1>'+
'<JobQues2><![CDATA[ ]]>'+
'</JobQues2>'+
'<JobQues3><![CDATA[ ]]>'+
'</JobQues3>'+
'<JobType>0|0</JobType>'+
'<JobAddnlBens>17,14,23,1,5,9,12,10</JobAddnlBens>'+
'<JobLocations>96,98,97</JobLocations>'+
'<JobEducations>8</JobEducations>'+
'<JobExperiences>10</JobExperiences>'+
'<JobCategories>1043,1050</JobCategories>'+
'<JobSubcategories>69896,69869</JobSubcategories>'+
'</JobDetails>'+
'</Transaction>'+
'</XML>';



function on_click()

{

if(window.ActiveXObject)
  {
     try
        {
        xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');

        }
     catch (ex)
     {
      xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');

     }
  }
 else if (window.XMLHttpRequest)
 {
   xmlhttp = new window.XMLHttpRequest();
   netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
 }

var xmlToSend = '<?xml version="1.0" encoding="utf-8"?>'+
'<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>'+
'<InsertXML xmlns="http://recpushdata.cyndigo.com/">'+
'<Jobs>'+XMLContent+'</Jobs>'+
'</InsertXML>'+
'</soap:Body>'+
'</soap:Envelope>';

var szUrl;
szUrl = 'http://recpushdata.cyndigo.com/Jobs.asmx?op=InsertXML';

xmlhttp.onreadystatechange = state_Change;

xmlhttp.open("Post", szUrl, true);

xmlhttp.setRequestHeader ("SOAPAction", "http://recpushdata.cyndigo.com/InsertXML");

xmlhttp.setRequestHeader ("Content-Type", "text/xml");

xmlhttp.send(xmlToSend);

}



function state_Change()

{

// if xmlhttp shows "loaded"

if (xmlhttp.readyState==4)

{

// if "OK"

if (xmlhttp.status==200)

{

alert("OK"+xmlhttp.responseText);

}

else

{

alert("Problem retrieving XML data "+xmlhttp.responseText);

}

}

}

    </script>

</head>
<body>
    <div>
        <h1>
            Click the button to call the web service</h1>
        <input type="button" onclick="return on_click();" value="OK" />
    </div>
    <div id="responseDiv">
    </div>
</body>
</html>

  
解决方案

XmlHttpRequest can only be used to call services local to the domain/server from where the page is being served.

Thus, if you're serving a page from:

http://www.example.com/page1

You cannot make an XmlHttpRequest to:

http://www.sample.com/webservice

这篇关于权限被拒绝错误 XMLHttpRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 15:28