谷歌富卡Javascript抛出错误

时间:2017-02-20 11:08:25

标签: javascript jquery asp.net

我正在尝试将Google富卡添加到我的电子商务商店产品页面。

     <script type="application/ld+json">
{
  "@context": "http://schema.org/",
  "@type": "Product",
  "name": $('#<%=lblProductTitle.ClientID %>').text();,
  "image": "http://www.example.com/anvil_executive.jpg",
  "description": "Sleeker than ACME's Classic Anvil, the Executive Anvil is perfect for the business traveller looking for something to drop from a height.",
  "mpn": "925872",
  "brand": {
    "@type": "Thing",
    "name": "ACME"
  },
  "aggregateRating": {
 -----------
     ----------
  },
  "offers": {
  -----------
     ----------
    }
  }
}
</script>

我的网站建立在Asp.net上,因此我必须使用clientId属性访问产品名称。一切看起来都不错。但是当我在这里查看页面https://search.google.com/structured-data/testing-tool时,它会抛出这样的错误 enter image description here 在线

  "name": $('#<%=lblProductTitle.ClientID %>').text();,

为了确认我的id选择器正常工作,我尝试了类似这样的事情

$(document).ready(function() { $('#<%=lblProductTitle.ClientID %>').text() });

它会提示正确的产品名称。谁能指出我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

为什么你使用jquery?

编辑:Google不看javascript数据

你能这样试试吗?

"name": $('#<%=lblProductTitle.ClientID %>').text();, to =&gt;

"name": "<%=lblProductTitle.Text%>",

 <script type="application/ld+json">
    {
      "@context": "http://schema.org/",
      "@type": "Product",
      "name": "<%=lblProductTitle.Text%>",
      "image": "http://www.example.com/anvil_executive.jpg",
      "description": "Sleeker than ACME's Classic Anvil, the Executive Anvil is perfect for the business traveller looking for something to drop from a height.",
      "mpn": "925872",
      "brand": {
        "@type": "Thing",
        "name": "ACME"
      },
      "aggregateRating": {
     -----------
         ----------
      },
      "offers": {
      -----------
         ----------
        }
      }
    }
    </script>