Does anyone know about working for jquery.load () by removing script tags loaded from external content?
There is a lot of documentation about this happening, but after something like 4 hours on the network, I can’t find a job?
I load dynamically generated divs - similar to the search results page - and I need to bind .click () to the element inside each dynamically generated div. I have a php file that works in html generation and returns all html as a string, but I cannot bind jquery.click () as the script tags containing the jquery function are removed.
here is the code that loads external content, calling the php file ...
$("#titles_wrap").load("m_scripts/m_php/titles_loader.php", function(){ $..some code });
and here is a loop from a php file that generates divs (this works fine) ...
$tag1='<script type="text/javascript">'; $tag2='</script>'; while($result_array = mysql_fetch_array($result)) { if($i2<=($titles_total)){ $_SESSION['titles_string'] .= '<li id="listItem_'.$i2.'"> <div id="titles_list_item"> <div id="titles_list_image_box" style="background-image: url(../../images/thumbs_test/'.$result_array[0].'); background-repeat: no-repeat; ">'.($i2+1).'</div> <div id="title_php_loader"></div> <div id="title_info_wrap"> <div id="title_current"><span class="title_current_grey" >current title: </span><br>'.$result_array[1].' </div> <div id="title_form_wrap"> <span class="title_current_grey" >new title: </span><br><input name="title_input_'.$i2.'" id="title_input_'.$i2.'" type="text" class="title_input"></input> <div id="title_send" class="title_send_'.$i2.'">GO</div> </div> </div> '.$tag1.' $(".title_send_'.$i2.'").click(function(){$("#title_php_loader").load("m_scripts/m_php/title_sender.php")}) '.$tag2.' </div> </li>'; $i2++; } }
Sorry if this second block of code is a bit on the overkill side - let me know if a simplified excerpt will be more useful. However, you can see on the eighth of the last line of PHP code a jquery function that must be written to each div with a dynamically assigned selector.
Of course, it may be that there are other errors in the code, but I cannot test it until I get .load () to stop it.
If anyone finds a solution to this - or even a workaround of limited grace - brilliant!
Thanks in advance,
Greetings
Scott
EDIT - EDIT - EDIT - EDIT - EDIT - EDIT - EDIT - EDIT
@TJ Crowder @Frug
Thanks for your help!
I just looked carefully at the pages participating in your demonstration, and yes, I see that you have a job. It seems surprising because they are those script tags, and there are many people who cannot make it work - unfortunately, I am one of them!
The only differences that I see between your demo and my code situation were
1) type declarations in the opening script tag,
2) you load the page with script tags as part of the DOM, while I load the output of the php string (I really don't think this matters tho), huh? By the time he gets into the client everything is going to the same thing, no?)
3), your .load call retrieved the whole page, while mine only returned items. Since then, I have changed the output line to include everything, and tags, but grrrrrr ... I still can’t get dam script tags that will be displayed in the DOM.
Any suggestions? There loads, about which I do not know, can be anything! thanks S