How to externalize json-ld and include in html doc

前提是你 提交于 2019-12-21 07:12:13

问题


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....


回答1:


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.



来源:https://stackoverflow.com/questions/26892397/how-to-externalize-json-ld-and-include-in-html-doc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!