1

I've been supplied some code from a 3rd party supplier to integrate on some of my webpages, which uses the jQuery plugin for jTemplates. Code looks similar to this:

<script type="text/html" id="item_template">
{#foreach $T.search.results as result}
    {$P.fieldExists($T.result, "thumbnail", "<img src=\"[[VALUE]]\" align=\"left\" border=\"0\">")}
{#/for}
</script>

The problem I've got, is in some web browsers, the browser makes a request for the image you can see in the code and looks like this:

http://localhost/MyWebapp/[[VALUE]]

Except, I think it shouldn't be making the request and I can't figure out if this is a browser defect, or the code is incorrect. I'm assuming because the content type is text/html in the script tag, the browser is parsing it as HTML.

Any insights here would be greatly appreciated.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Jonathan
  • 191
  • 2
  • 3
  • 8
  • How does the HTML look like that's actually generated? That foreach is executed on the server. Oh, and change text/html into text/javascript - the ONLY acceptable value for script tags. – Mörre Mar 03 '11 at 12:44
  • Correction - I mean "generated Javascript", since we are looking at the contents of a script tag. Anyway, we need to see what the browser sees, not the server template. – Mörre Mar 03 '11 at 12:53
  • Hello Morre, apologies if I've misunderstood you. The code I attached in the question is the actual HTML/script which is in the returned mark-up from the server to browser. I think the jTemplate plugin (for Jquery) executes the code within the browser and Javascript generates the HTML on-the-fly after it retrieves a set of results using AJAX. – Jonathan Mar 03 '11 at 18:29

1 Answers1

0

Yes, you are right, the text/html type may be the culprit here. Try x-application/template or text/template or something like that. Also make sure that you have a DOCTYPE, quirks mode may also play a role here.

chiborg
  • 26,978
  • 14
  • 97
  • 115
  • 1
    There is only one type acceptable for HTML script tags, and that is text/javascript... :) Also see http://javascript.crockford.com/script.html However, at least as important is that he shows us the actual HTML and not the server template, since the question is about the browser. – Mörre Mar 03 '11 at 12:49
  • This is not true. You can use other values - if the browsers does not support the type, it will ignore it. And in this case, it's especially useful, since the script tags do not contain script but **templates** that contain HTML which should be fed verbatim to the template library. Using an unusual type means the bowser will not parse the text. – chiborg Mar 04 '11 at 12:36