如何外部化json-ld并包含在html文档中 [英] How to externalize json-ld and include in html doc

查看:91
本文介绍了如何外部化json-ld并包含在html文档中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将json-ld外部化并将其包含在如下所示的html文档中:

 < script type = text / javascriptsrc =http://www.example.com/data123.jsonld>< / script> 

似乎没有关于这个在线的任何文档....

解决方案

你不能那样做。您应该使用 AJAX 请求获取 json 使用 jQuery

JS

  $(函数(){
$ .getJSON(data123.jsonld,函数(数据){
$('。json').text(data);
});
});

HTML

 < div class =json>< / div> 

如果您的json文件不在您的文件系统中(跨域)你应该尝试像


Is it possible to externalize json-ld and include it in an html document like this:

<script type="text/javascript" src="http://www.example.com/data123.jsonld"></script>

There doesn't seem to be any documentation about this online....

解决方案

You can't do that. You should get the json with an AJAX request.

You can do it easy with jQuery

JS

$(function(){
  $.getJSON("data123.jsonld", function(data) {
      $('.json').text(data);   
  });
});

HTML

 <div class="json"></div>

If your json file is not in your file system (cross domain) you should try something like this.

这篇关于如何外部化json-ld并包含在html文档中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆