If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

JS functions not working while loading html using Ajax

friends,
I am trying to load a html into some div using ajax tech. the UI I am getting. but not the js functions. I am embedding the js file w.r.t external html file.
for eg:
from Main.html page I want to load local.html file.
In local.html file I have specified the related js file local.js.
But once I load the local.html into some div of the Main.html, the js functions in local.js is not working. I think this happens due to src path problem. but the onLoad function in local.html is also not working.

Re: JS functions not working while loading html using Ajax

You cannot use AJAX to import other JavaScripts, because JavaScript cannot be written dynamically. Functions and variables can be created dynamically, but that is by code already in existence within the page.

If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Re: JS functions not working while loading html using Ajax

Thanks for the reply. In fact I don't want to import javascript files directly. The html file that I am loading has js file info to embed in it. but thing is that, when I load an html file it onload event and any function invocation is not working. There is were I am stuck in.

Re: JS functions not working while loading html using Ajax

Ok friend, I understood. I changed the way to parse the html string and trying to load the scripts. everything is working fine. But any onload function in body tag not executed.
I need to execute it once the html view content is loaded in the DOMElement (div).
I tried with adding event listener. Just have look at the code.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.