开发者

Jquery code in page called via ajax

开发者 https://www.devze.com 2023-01-21 14:57 出处:网络
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

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 inclu开发者_开发知识库de 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.


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.


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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消