2013-04-27 56 views
0

我正在为Office编写应用程序,在那里我计划使用AJAX从内部网站动态地将内容加载到办公室应用程序。我有以下JS功能。当执行达到a.open()功能,它显示了一个错误:Microsoft Office Web App中的AJAX

Unhandled exception at line 31, column 21 in https://localhost:44304/App/Home/Home.js 

0x80070005 - JavaScript runtime error: Access is denied. 

-

function getDataFromSelection() { 
    Office.context.document.getSelectedDataAsync(Office.CoercionType.Text, 
     function (result) { 
      if (result.status === Office.AsyncResultStatus.Succeeded) { 

       var a = new XMLHttpRequest(); 
       a.onreadystatechange = function() { 
        if (a.readyState == 4 && a.status == 200) { 
         var jSONstr = a.responseText; 
         var obj = jQuery.parseJSON(jSONstr); 
         showSearch(obj); 
        } 
       }; 

       a.open("GET", "http://some.external.site/page.php?query=" + result.value, true); //This has got the error 
       a.send(); 
      } 
      else { 
       app.showNotification('Damn!:', result.error.message); 
      } 
     } 
    ); 
} 

是AJAX在Office应用程序支持?我如何做其他(工作)方式的确切的事情?

PS:我使用Visual Studio 2012年的Win8

回答

1

,因为你试图使通过AJAX一个跨站点请求被触发的错误。

浏览器很少允许这种请求,所以您应该找到一种解决方法,向处理服务器到服务器通信的服务器端脚本发出JSONP请求或ajax请求。

相关问题