View Full Version : Cannot get JS content from AJAX page to load

12-09-2009, 08:30 PM
I have been searching online for hours, but it is possible I'm just not thinking of the correct keywords. I have included a basic illustration of the current setup (which does not work). The issue lies with the page that is the desired output. I have a far deeper issue which I have narrowed down to javascript on the final .asp page not loading at all.

On default.asp, I am calling a function contained in 'ajax_call-contentselection.js'

<a onclick="func_displaycontents('restaurants'); return false">displayajaxcontent</a>

Honestly, I don't believe the following piece of code (ajax_call-contentselection.js) is relevant, as it is standard ajax code, but just in case:

function func_displaycontents(var_type){
var xmlHttp = GetXmlHttpObject();
var url = "../_include/ajax_display-contentselection.asp";
url += "?type="+var_type;

if (!xmlHttp){
alert ("Browser does not support HTTP Request")

if(xmlHttp.readyState == 1){
document.getElementById("div_ajaxfillattractions").innerHTML = "<div style='padding-top:50px;color:white;width:930px;text-align:center;'><img src='../_images/ajax-loader.gif'/><br/>Loading...</div>";
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
xmlHttp.open("GET", url, true);

The other contents of "ajax_display-contentselection.asp" are displayed properly in "div_ajaxfillattractions" of "default.asp", but no javascript code on that page loads. If I use "ajax_display-contentselection.asp" as an include file on "default.asp", I get the javascript alert of 'Success', but when I initiate the AJAX it does not work, so I know there isn't a problem with the javascript.

Please let me know if I sucked at explaining something, or more detail is needed.

Thanks in advance,

Old Pedant
12-10-2009, 01:20 AM
Putting <script> into the innerHTML of something will *NOT* cause that <script> to execute!


Inline <script> tags like that are only executed by the browser when they are encountered during page load. Never afterwards.

Think about it: If they were executed at any other time, and you had HTML code like this:


then what would prevent the browser from writing "foo" to that div on every screen redraw? (And screen redraws happen for most any little reason.)

Try changing your ajax_display-ContentSelect.asp page to just this:

Response.Write "It is now " & Time()

And tell us what happens.

12-10-2009, 03:07 PM
I will just have to rearchitect some stuff to get around that problem. Thanks for the response.