View Full Version : Why javascript loaded in ajax not working ?
ravindranathbe
07-14-2009, 02:17 PM
Why javascript loaded in ajax not working ?
I load a javascript file using ajax - but found to not work.
This js file must be used only for that page.
ckeyrouz
07-14-2009, 03:39 PM
Post some come please to check the problem.
A1ien51
07-15-2009, 02:52 AM
You can not set javascript with innerHTML. It will not be evaluated. If you want to do it, you need to evaluate it yourself. If you use a library such as Prototype.js or JQuery, they have it built in. If you are just fetching a JavaScript file, there is no need to use Ajax, you just need createElement and appendChild.
Eric
mioot
07-18-2009, 01:23 PM
use these code to upend the javascript file.
var head = document.getElementsByTagName('head').item(0);
var url ="filepath";
try
{
var s = document.createElement('script');
url = url + '?random=' + sRn;
s.src = url;
s.type = 'text/javascript';
s.defer = true;
s.id = 'visitorConsole';
void(head.appendChild(s));
}
catch(e){
}
rnd me
07-19-2009, 02:19 AM
if you are loading a .js file, simply call eval(obj.responseText), where obj is the AJAX object...
if you are loading html, you'll have to find the script tag text using RegExp, and then call eval() separately on each one in order.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.