简体   繁体   中英

Why is JSON binding inside jQuery template not parsed inside tag?

I have an upload script inside an XSL template, which lets JavaScript upload a file. It's inside an XSL template. The upload handler file (upload.php) will return a JSON object when the file is uploaded.

<script id="template-download" type="text/x-jquery-tmpl">
<a href="${url}">${url}</a>
</script>

But when I see the output, only the second ${url} is parsed. Propably a JSON binding ${the_binding} (which is extracted from the JSON object) won't get parsed while it's the value of an attribute.

Thus, the result is the following:

<a href="${url}">http://google.com/search?q=this+JSON+binding+is+parsed</a>

How to let the binding inside href attribute get it's proposed value?

Here is an example of that template being rendered correctly :

$('#template-download').tmpl({url: 'http://google.com'}).appendTo('body');

If that's not working for you, then there must be something wrong in how you're rendering the template.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM