无法识别Access-Control-Allow-Origin

时间:2018-05-21 11:30:25

标签: ajax web-services sharepoint

我需要在SharePoint newform中使用JavaScript / jquery从外部服务器获取员工信息。 首先我写下了代码

function CallClientIDWebSerivce() {
  var URL = "http://applicationsrv/HRMServices.asmx/GetEmployeeInfo";
  alert(URL)
  $.ajax({
      type: "POST",
      url: URL,
      dataType: "xml",                     
      data:"userName:"+username+",date:"+today()+",modified_by:"+username+"}" ,          
      contentType: "application/xml; charset=utf-8",
          success: function (response) {
          alert(response);
      },
      failure: function (msg) {
          alert('failure');
          dialog.innerHTML = "Some Unknown Error Occured, Please Try Again";
      }
  });
}

并收到错误

  

XMLHttpRequest: Network Error 0x80070005, Access is denied.

我谷歌我发现Cross-Origin Resource Sharing发生了  所以我将Access-Control-Allow-Origin : "*",添加到a​​jax,但浏览器不会识别它并收到错误。

1 个答案:

答案 0 :(得分:0)

您不必在客户端做任何事情。浏览器自动完成。但应将Share Point配置为允许来自其他域的脚本请求。 在这里查看如何配置共享点https://social.msdn.microsoft.com/Forums/security/en-US/8dfc2b5e-1136-45a8-9d85-73ce9c98fd06/how-to-enable-cors-on-sharepoint-online-site?forum=sharepointdevelopment