Executing Javascript from another page using AJAX
Question
I am trying to get a specific div with some Javascript inside that div, from another page using AJAX, but for some reason the Javascript doesn't load... I can only see the HTML.
What am I doing wrong? This is my code:
$.ajax({ url: 'web.php', type: 'GET', datatype: 'html', success:
function (html) {
var data = $('#content',$(html)).html();
YAHOO.plugin.Dispatcher.process($('#content').get(0), data);
}
});
Solution
use this
$.ajax({ url: 'web.php', type: 'GET', datatype: 'html', success:
function (html) {
$("script").append(html);
var data = $('#content',$(html)).html();
YAHOO.plugin.Dispatcher.process($('#content').get(0), data);
}
});
OTHER TIPS
If your .js isn't loading, there's probably a syntactical error somewhere and your browser will use the previously cached version. I'd go back over my last few changes to see what I messed up - a missing bracket, paren, semicolon, etc.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow