【发布时间】:2017-03-15 10:06:20
【问题描述】:
我正在使用JavaScript API for Excel 制作 Excel 插件。插件入口为addin.html,调用JS、CSS文件。所有文件都托管在www.myexample.com。
当我们点击插件中的一个按钮时,它会弹出一个window.open("https://www.myexample.com/post/", "popup")的浏览器窗口。以post.html为模板的页面由angularjs和ui-router构建。服务器和客户端也托管在www.myexample.com。
post.html 的控制器需要不定时向addin.html 发送请求。例如,post.html 向addin.html 发送地址A1,并期望收到Cell A1 的当前值。 addin.html 很容易通过 JavaScript API for Excel 从 Excel 使用一些异步函数 获取单元格值。而我的问题是如何在post.html 的控制器中实现请求(从地址获取单元格值)。
如果我们使用$http.post,是否可以向没有服务器的addin.html发送请求?
var getValue = function (address) {
return $http.post('...', { address: address })
.then(function (res) {
// maybe do something with res
return res
}
}
如果我们使用postMessage,我们可以在post.html 中实现监听器,它们是反应式的。我无法想象如何主动发送请求并等待响应。
有人可以帮忙吗?
【问题讨论】:
标签: javascript http-post ms-office office-js postmessage