Jquery code in page called via ajax
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
精彩评论