次のように、$http を介してページ上の JSON-LD データを取得して出力しようとしています。
angular.element(document).ready(function(){
$http({
url:'/product-init',
method:'POST',
data:{product_id:$scope.product_id}
}).then(function(d){
$scope.product= d.data;
$scope.jsonLd={
"@context":"http://schema.org",
"@type":"Product"
// atc.....
}
$('#json-ld-content').html(JSON.stringify($scope.jsonLd));
},function(d){
alert('product init error');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script type="application/ld+json" id="json-ld-content"></script>
Web インスペクター (「要素」タブ) で出力を確認できますが、[チェック] を実行すると何も表示されません。
JavaScriptでscriptタグを作成してから html を設定しても、同様に役に立ちません。また、AJAX を介して JSON-LD をロードする例も見つけました。正常に動作します。
私のケースと上記の例の違いは何ですか? コードを修正するにはどうすればよいですか? 前もって感謝します。