tags:

views:

30

answers:

3

Im using arte for jquery to call a page via ajax every 10 seconds. It calls to one of my php pages, that php page queries the database and spits back html code. In that html code are some jquery calls. The problem is those calls dont work unless I include the jquery script in the php file being called. But that causes issue with jquery code on the main page that is calling the php file. Basically how can I get jquery inside html that is return from an page called via ajax to work? Here is the code that calls the php file:

     $(document).ready(function(){
  $.arte({'ajax_url':'ajax_list.php','on_success':update_field}).start();
  $.arte().set('time',10000);
  });

 function update_field(data){
  $("#glist").html(data);
 }

So ajax_list.php echos back an html output. Inside that html output are some jquery calls. Again these dont work unless I include the jquery library in ajax_list.php. But then that causes issues with other jquery calls outside of ajax_list.php on the same page. Is there a way to include the jquery library in the main page calling ajax_list.php and have the jquery code inside the return results work? Hope this makes sense.

A: 

Unless the arte library's doing some pretty deep magic, the inline JS in the html returned by ajax_list.php should never fire. JS that's dynamically entered into the DOM by JS isn't evaluated.

You might be able to get around the problem by binding .live or .delegate handlers, depending on what the inline JS is.

DDaviesBrackett
Or by simply using `eval()`.
Peter Ajtai
Well for example I use jquery thickbox. I include the files in the parent window that is making the ajax call to the php file. Then the returned data from the php file has the code to execute thickbox on a link. But that does not work at all. I have to include the thickbox files in the html returned from the php file. The problem with that is the arte library refreshes automatically every 30 seconds so basically thickbox gets called over and over again so when you do click a link that uses thickbox it shows as many windows popping up as many times it refreshed.
John
A: 

Is it possible for you to write your returned function as a function in the original page, return your data as a JSON object consisting of

HTML->'Your HTML',

DATA=>array(elements or whatever),

use getJSON, set your HTML as the JSON.HTML object in the JSON array, and send the object(s) in you JSON.DATA object to your function to execute?

FatherStorm
Well I guess I could actually just return the data from the database into json via the ajax call and use that object to iterate through to build the html on the parent page itself. Is that pretty much what you were suggesting?
John
A: 

Well mainly my issue was with thickbox code in data returned from an ajax call. The link I found that resolved my issue is here Thickbox on ajax generation

John