Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    NW Iowa
    Posts
    185
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Cannot get JS content from AJAX page to load

    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'

    Code:
    <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:
    Code:
    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")          
    		return     
    	}    
    		
    	xmlHttp.onreadystatechange=function(){     
    	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"){
    			document.getElementById("div_ajaxfillattractions").innerHTML=xmlHttp.responseText;
            	}     
    	};     
    	xmlHttp.open("GET", url, true);     
    	xmlHttp.send(null);
    }
    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,
    Matt
    Last edited by mattboy_slim; 12-09-2009 at 07:48 PM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,588
    Thanks
    80
    Thanked 4,497 Times in 4,461 Posts
    Putting <script> into the innerHTML of something will *NOT* cause that <script> to execute!

    Period.

    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:
    Code:
    <div>
        <script>document.write("foo");</script>
    </div>
    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:
    Code:
    <%
    Response.Write "It is now " & Time()
    Response.End
    %>
    And tell us what happens.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Dec 2002
    Location
    NW Iowa
    Posts
    185
    Thanks
    9
    Thanked 0 Times in 0 Posts
    I will just have to rearchitect some stuff to get around that problem. Thanks for the response.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •