I have a issue:
while i call a inline script (wich uses jQuery too) from another page with ajax – it seems, that jQuery is no more defined (?), and I cannot use any of jQuery functions, that should be applied (according to inline script) to content.
It’s basically a news list, which holds links to particular news items. I prefer using inline-script at this time, because I won’t need this functionality elsewhere.
$.ajax({
url: href,
cache: false,
success: function(html){
$('#fancy_ajax').append($(html).find('.mainContentPadded'));
}
});
As you can see, I’m simply calling a part of another page and appending its contents to page.
When I load full page (not the part of it) – jQuery works as expected (that’s why I came across the idea, that it needs to be “rebinded”).
Thank you!
So if I understand your question correctly you have some JavaScript contained within the html variable ? If so it will not work, because JavaScript that is retrieved from an AJAX hit is not executed by the browser due to security risks.
I recommend you include the necessary javascript code in your page that is initiating the the Ajax request so that it is already available when you append the new content.
*edit…
monksp added a great link as a comment that shows how to have jQuery do exactly what you want.
Here’s also some code to do the same but manually:
Here’s the content of testjs.json:
And finally there are a bunch of existings plugins and other things to include javascript dynamically. I used YUI Get in the past: http://developer.yahoo.com/yui/3/get/