0

I want to print the audio tag in html what should I add in my html code

<script ></script>
$(document).ready(function() 
{            
  // Request 
  jQuery.getJSON
  (
    ,
    {
      prot_vers: 2, cl_login: " ", cl_app: " ", cl_pwd: " ", 
      req_voice:"heather22k", 
      req_text:$("#demo_voices_textarea").val()
    },
    function(data) 
    {
      //api response management 
      $("#demo1player").html("<audio src='"+data.snd_url+"' controls='controls' />"); 
    }      
  );
});

and my html code is here

 <form name="Test"  method="post">
<textarea name="demo_voices_textarea" rows="4" cols="20">Hello World !</textarea>
<br/>
<input type="submit" value="Create sound!">
</form>

many thanks

Afnan M
  • 11
  • 1
  • 2

4 Answers4

0

Instead of .html() use .text() as shown :-

$("#demo1player").text("<audio src='"+data.snd_url+"' controls='controls' />");
Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69
0

Use <pre>...</pre> tag

$("#demo1player").html("<pre><audio src='"+data.snd_url+"' controls='controls' /></pre>"); 
void
  • 36,090
  • 8
  • 62
  • 107
0

Use &lt; and &gt; instead < and > :

$("#demo1player").html("&lt;audio src='"+data.snd_url+"' controls='controls' /&gt;");
Derozer
  • 69
  • 5
0

I would use the $(element).text() function. A few days ago I've looked how to escape html in javascript. I found following Link: Escaping HTML strings with jQuery

I think it should work for your purpose.

Community
  • 1
  • 1
perber
  • 79
  • 7