3

After trying to get this to work for hours I turn to you guys.

I want to load a page into a div tag using jQuery. The page I'm loading has a HTML5 media player:

<h3> {{ title }} </h3> <audio controls autoplay> <source src="/static/media/{{ song }}" type="audio/mp3"> Your browser does not support this audio format. </audio> 

when I load the page directly it works fine. When I do it like this:

<script type="text/javascript"> $(function() { $( ".song" ).click(function() { alert('hello') }); $("#mp").load("/playsong?song_id=53847b72936aa27d640039f7"); }); </script> 

It works fine (and the hello message works!)

But when I put the load command inside the .click() event, it does not work:

<script type="text/javascript"> $(function() { $( ".song" ).click(function() { alert('hello') $("#mp").load("/playsong?song_id=53847b72936aa27d640039f7"); }); }); </script> 

I am using flask on the backend and in all cases the code on the backend gets executed.

5
  • missing ; after alert. Not sure if that could be causing any issue Commented Jun 6, 2014 at 14:24
  • 1
    Errors in the browser console? Commented Jun 6, 2014 at 14:25
  • @cr0ss Ya not the issue, added automatically by js interpreter Commented Jun 6, 2014 at 14:25
  • 1
    Does your templating engine process the ajaxed data. Commented Jun 6, 2014 at 14:26
  • 1
    Instead of load try $("#mp").html("/playsong?song_id=53847b72936aa27d640039f7"); Commented Jun 6, 2014 at 14:33

1 Answer 1

1

try this:

<script type="text/javascript"> $(function() { $(document).on("load","#mp","/playsong?song_id=53847b72936aa27d640039f7"); $( ".song" ).click(function() { alert('hello') $( "#mp" ).trigger( "load" ); }); }); </script> 

let me know if this works, 'cause I have a backup answer!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.