(Angular) Js 使用 AJAX return 数据作为 URL 嵌入 MS Word 文档
(Angular) Js embedding an MS Word doc using AJAX return data as the URL
[更新]有50点奖励,我会加到200点工作fiddle
[更新] 虽然我更喜欢 AngualrJs 解决方案,但我也会接受纯 JS - 任何能让我走出僵局的东西......对我的服务器的 GET 调用 returns a URL我想将该文档嵌入我的 HTML
参考,@MaximShoustin 的回答似乎很完美,但我遇到了问题。
那个解决方案中的 URL 是硬编码的,但我想通过 AJAX 获得我的。当我这样做时,文档没有嵌入,但我在开发者控制台中没有看到任何错误。
我做了 this fiddle,我在其中添加了这些行
到HTML
<iframe ng-src="{{cvUrlTrusted_2}}"></iframe>
并且,到控制器
app.controller('Ctrl', function($scope, $sanitize, $sce, $http) {
已添加, $http
和
// new stuff follows
var url = 'http://fiddleapi.rf.gd/getDocuemntUrl.php';
/* The URL contains this code ...
<?php
echo('https://d9db56472fd41226d193-1e5e0d4b7948acaf6080b0dce0b35ed5.ssl.cf1.rackcdn.com/spectools/docs/wd-spectools-word-sample-04.doc');
?>
*/
$http.get(url)
.success(function(data, status, headers, config)
{
var cvTrustedUrl_2 = 'http://docs.google.com/gview?url=' + data.trim() + '&embedded=true';
$scope.cvTrustedUrl = $sce.trustAsResourceUrl(cvTrustedUrl_2);
})
.error(function(data, status, headers, config)
{
alert('Urk!');
});
如果您在 http://fiddleapi.rf.gd/getDocuemntUrl.php 调用 API,您将看到它 returns 与解决方案中硬编码的文档 URL 相同。
请,先检查一下我的代码,免得写错了。
长描述,简短问题:如何使用 [=56= 将 AJAX API 返回的 URL 文档嵌入到 HTML 文档中]?免费免费分叉fiddle.
您的 fiddle 由于跨域问题无法使用:http://fiddleapi.rf.gd/getDocuemntUrl.php
所以我加载了简单的 JSON 文件,内容为:
{
"val":"https://d9db56472fd41226d193-1e5e0d4b7948acaf6080b0dce0b35ed5.ssl.cf1.rackcdn.com/spectools/docs/wd-spectools-word-sample-04.doc"
}
和:
$http.get('data.json').then(function (resp){
var cvTrustedUrl_2 = 'http://docs.google.com/gview?url=' + resp.data.val + '&embedded=true';
$scope.cvUrlTrusted_2 = $sce.trustAsResourceUrl(cvTrustedUrl_2);
});
它工作正常,所以问题出在你的 http://fiddleapi.rf.gd/getDocuemntUrl.php 中,因为这个 URL 在 Postman 中也不起作用。我得到:
This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support
确保你配置好
[更新]有50点奖励,我会加到200点工作fiddle
[更新] 虽然我更喜欢 AngualrJs 解决方案,但我也会接受纯 JS - 任何能让我走出僵局的东西......对我的服务器的 GET 调用 returns a URL我想将该文档嵌入我的 HTML
参考
那个解决方案中的 URL 是硬编码的,但我想通过 AJAX 获得我的。当我这样做时,文档没有嵌入,但我在开发者控制台中没有看到任何错误。
我做了 this fiddle,我在其中添加了这些行
到HTML
<iframe ng-src="{{cvUrlTrusted_2}}"></iframe>
并且,到控制器
app.controller('Ctrl', function($scope, $sanitize, $sce, $http) {
已添加, $http
和
// new stuff follows
var url = 'http://fiddleapi.rf.gd/getDocuemntUrl.php';
/* The URL contains this code ...
<?php
echo('https://d9db56472fd41226d193-1e5e0d4b7948acaf6080b0dce0b35ed5.ssl.cf1.rackcdn.com/spectools/docs/wd-spectools-word-sample-04.doc');
?>
*/
$http.get(url)
.success(function(data, status, headers, config)
{
var cvTrustedUrl_2 = 'http://docs.google.com/gview?url=' + data.trim() + '&embedded=true';
$scope.cvTrustedUrl = $sce.trustAsResourceUrl(cvTrustedUrl_2);
})
.error(function(data, status, headers, config)
{
alert('Urk!');
});
如果您在 http://fiddleapi.rf.gd/getDocuemntUrl.php 调用 API,您将看到它 returns 与解决方案中硬编码的文档 URL 相同。
请,先检查一下我的代码,免得写错了。
长描述,简短问题:如何使用 [=56= 将 AJAX API 返回的 URL 文档嵌入到 HTML 文档中]?免费免费分叉fiddle.
您的 fiddle 由于跨域问题无法使用:http://fiddleapi.rf.gd/getDocuemntUrl.php
所以我加载了简单的 JSON 文件,内容为:
{
"val":"https://d9db56472fd41226d193-1e5e0d4b7948acaf6080b0dce0b35ed5.ssl.cf1.rackcdn.com/spectools/docs/wd-spectools-word-sample-04.doc"
}
和:
$http.get('data.json').then(function (resp){
var cvTrustedUrl_2 = 'http://docs.google.com/gview?url=' + resp.data.val + '&embedded=true';
$scope.cvUrlTrusted_2 = $sce.trustAsResourceUrl(cvTrustedUrl_2);
});
它工作正常,所以问题出在你的 http://fiddleapi.rf.gd/getDocuemntUrl.php 中,因为这个 URL 在 Postman 中也不起作用。我得到:
This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support
确保你配置好