1

I would like to know how can I insert a string into a javascript code like in the example below:

     <script type="application/ld+json">
        {
          "@context": "http://schema.org",
          "@type": "Restaurant",
          "name": "Dave's Steak House",
          "address": {
            "@type": "PostalAddress",
            "streetAddress": "148 W 51st St",
            "addressLocality": "New York",
            "addressRegion": "NY",
            "postalCode": "10019",
            "addressCountry": "US"
          }
        }
        </script>

The problem is that when I try to insert the String between js it appears interpreted as HTML code with %, &20 etc. I have tried with ?html, escape, no escape, ?string, ?js_string, etc.

That's the String:

 {
          "@context": "http://schema.org",
          "@type": "Restaurant",
          "name": "Dave's Steak House",
          "address": {
            "@type": "PostalAddress",
            "streetAddress": "148 W 51st St",
            "addressLocality": "New York",
            "addressRegion": "NY",
            "postalCode": "10019",
            "addressCountry": "US"
          }
        }

And the code:

${myString}
the_unknown_spirit
  • 2,518
  • 7
  • 34
  • 56
D. Joe
  • 11
  • 1
  • Possible duplicate of [How to insert a large block of HTML in JavaScript?](http://stackoverflow.com/questions/16270761/how-to-insert-a-large-block-of-html-in-javascript) – Gaurava Agarwal Jul 11 '16 at 10:54
  • You do it like `${myString}` usually... can you explain better what happens then? What do you mean it's interpreted as HTML code? What's `%` and `&20`? – ddekany Jul 11 '16 at 17:21
  • For example whitespaces are interpreted as ` ` I mean that all is interpreted as ASCII code. – D. Joe Jul 12 '16 at 06:57

0 Answers0