Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding YouTube Video with jQuery Templates - C#

I'm using jQuery Templates to Embed user posted YouTube vids. I am able to fetch the video id and save it into the database and everything is working correctly. However when trying to embed the video with jQuery Templates as follows:

{{if streamObj.TypeOf == 3}}
            <object width="425" height="350" data='http://www.youtube.com/v/${VideoId}' type="application/x-shockwave-flash">
            <param name="src" value='http://www.youtube.com/v/${VideoId}' /></object>
{{else}}

I get the following error: "NetworkError: 404 Not Found - http://www.youtube.com/v/"

${VideoId} and streamObj.TypeOf return correctly. But that's the error. What could be causing this? Thank you.

like image 381
user1027620 Avatar asked Nov 26 '11 07:11

user1027620


1 Answers

Try this.

<object width="425" height="350" data='http://www.youtube.com/v/' + ${VideoId} type="application/x-shockwave-flash">
    <param name="src" value='http://www.youtube.com/v/' + ${VideoId} />
</object>

Or perhaps better.

var videoUrl = 'http://www.youtube.com/v/' + ${VideoId};

<object width="425" height="350" data=videoUrl type="application/x-shockwave-flash">
    <param name="src" value=videoUrl />
</object>

I believe that the template tag in your code isn't evaluated corretly due to the fact that the template tag is set as a part of a js string value.

like image 135
Benny Johansson Avatar answered Oct 21 '22 11:10

Benny Johansson