php - returning javascript via ajax but it doesnt work -


i trying links appear after clicking business name appear in light box. on standalone page, possible send same code through ajax, not call light box anymore. help?

this original file, supposed represent 3rd party publisher site, integrating our code:

<html> <head>     <script type="text/javascript" src="lib/js/jquery-latest.js"></script>     <link rel="stylesheet" href="css/prettyphoto.css" type="text/css" media="screen" charset="utf-8" />     <script src="lib/js/jquery.ppo.js" type="text/javascript" charset="utf-8"></script>     <script src="lib/js/sp.js" type="text/javascript" charset="utf-8"></script>          </head> <body>     publisher's website. <br>     <div id="bizname1" onclick="showcomp(this.innerhtml)" id="bizname" class="bizname">click here - event should substituted 'on load'.</div><br><br>  lots of data company here  <br /> <div id="txthint"><b>company info listed here.</b></div>   </body> </html> 

this ajax script, showcomp.js:

function showcomp(str) { if (str=="")   {     document.getelementbyid("txthint").innerhtml="";     return;   } // code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest();  xmlhttp.onreadystatechange=function()   {   if (xmlhttp.readystate==4 && xmlhttp.status==200)     {         document.getelementbyid("txthint").innerhtml=xmlhttp.responsetext;     }   } xmlhttp.open("get","getbutton.php?q="+str,true); xmlhttp.send(); } 

this getbutton.php file called ajax function:

error_reporting(e_all); ini_set('display_errors', 1); session_start();  include('config.php');   init_connection();  $sql=select content db;// part works fine, actual sql query not inserted here.  $result = mysql_query($sql);  while ($row = mysql_fetch_object($result)) {      $companyname = $row->result1;     $contenturl = $row->result2;     //echo $companyname;     //echo $contenturl;  ?>    <html> <head>  </head> <body>     <a href="http://www.youtube.com/embed/dudfbixw6do?iframe=true&width=640&height=390" rel="prettyphoto" title="my caption"> video in iframe     <img src="images/thumb-1.jpg" width="100" height="40" alt="video in iframe" />     </a> <a href="demo/vidrefer.php?iframe=true&width=500&height=410" rel="prettyphoto" title="my caption"> vidrefer in iframe     <img src="images/thumb-1.jpg" width="100" height="40" alt="vidrefer in iframe" /> </a> <br />   </body> </html>   <?php }  //echo out button here. give button needs launch light box.  echo " <br> <div id='button'> button </div> "; //mysql_close($con); ?> <script id="ppready" type="text/javascript" charset="utf-8">     $(document).ready(function(){     $("a[rel^='prettyphoto']").prettyphoto(); }); </script> 

please if can see why not working! thank you.

i fixed this! problem due fact javascript acted before loaded new elements via ajax. had load elements in before ajax call , hey presto!

an alternative solution have been use live() or livequery() in jquery. have kept jquery acting on elements both before , after loaded dom. simples.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -