(角)JS使用AJAX返回数据作为URL嵌入MS Word文档 [英] (Angular) Js embedding an MS Word doc using AJAX return data as the URL
问题描述
[更新]有50点的奖励,对于工作中的小提琴,我将奖励200点
[Update] there is a 50 point bonus, which I will up to 200 for a working fiddle
[更新]虽然我更喜欢AngualrJs解决方案,但我也将接受纯JS-可以解决这个僵局的任何事情...对服务器的GET调用返回一个URL,并且我希望将该文档嵌入到HTML
[Update] while I prefer an AngualrJs solution, I will also accept plain JS - just anything to get me over this impasse ... a GET call to my server returns a URL and I want to embed that document into my HTML
参考,@ MaximShoustin的回答似乎很完美,但我遇到了问题。
With reference to my previous question, @MaximShoustin 's answer seemed perfect, but I am having problems.
该解决方案中的URL进行了硬编码,但我想通过AJAX来查找。当我这样做时,文档没有被嵌入,但是在开发人员控制台中没有看到错误。
The URL in that solution there is hard coded, but I want to get mine by AJAX. When I do, the document is not embedded, but I see no error in the developer console.
我创建了这个小提琴,在其中我将这些行
I made this fiddle, where I added these lines
添加到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 ,您将看到它返回的URL与解决方案中的硬编码相同。
If you invoke the API at http://fiddleapi.rf.gd/getDocuemntUrl.php you will see that it returns the same document URL as was hard coded in the solution.
请 ,请先检查我的代码,以免我弄错了。
Please, first check my code, lest I have made a mistake.
简短的简短说明:如何使用AngularJS将URL从AJAX API返回的文档嵌入HTML文档中?免费免费拨弄小提琴。
Long description, short question : how can I embed a document who's URL is returned from an AJAX API into an HTML document using AngularJS? Free free to fork the fiddle.
推荐答案
由于跨域问题,您的小提琴无法正常工作: http://fiddleapi.rf.gd/getDocuemntUrl.php
Your fiddle doesn't work because of cross domain problem: http://fiddleapi.rf.gd/getDocuemntUrl.php
所以我加载了包含内容的简单JSON文件:
So I loaded simple JSON file with content:
{
"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中也无法使用。我得到:
It works fine so the problem is in your http://fiddleapi.rf.gd/getDocuemntUrl.php because this URL doesn't work in Postman too. I get:
该站点需要使用Javascript,请在您的浏览器中启用Javascript或使用支持Javascript的浏览器
This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support
请确保配置正确
这篇关于(角)JS使用AJAX返回数据作为URL嵌入MS Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!