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
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JavaScript Not Evaluating when called using XMLHTTPRequest

    ok,

    I have a page with a div on it (titled 'mainDoc') and a serise of links,

    When the user clicks on a link the following code returns the HTML source of another webpage to a string.

    I then dump the string into the div using innerHTML

    Code:
    function getHeader(tab){
    var xmlhttp=false;
    	try {
    		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    	} catch (e) {
    		try {
    			xmlhttp = new
    			ActiveXObject("Microsoft.XMLHTTP");
                } catch (E) {
                	xmlhttp = false;
    			}
    	}
    	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    		xmlhttp = new XMLHttpRequest();
    	}
    
    	var doc = "tab_content/"+tab+".php";
        xmlhttp.open("GET", doc, true);
        xmlhttp.onreadystatechange=function() {
    		if (xmlhttp.readyState==4) {
    			var main = document.getElementById('mainDoc');
    			var html = xmlhttp.responseText;
    			main.innerHTML = html;
    			}
    	}
    	xmlhttp.send(null)
    return;
    }
    The problem is this:

    In the 'return string' (i.e var html ) there is some JS code.
    This code does not get executed, ever...

    so for example:

    if var html contained

    Code:
    <script>alert('here');</script>
    No alert would happen.

    any ideas or help would be great!
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #2
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    You'll probably have to extract it then eval() it.
    Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
    I code to specs, and test only in Firefox (unless stated otherwise).

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, in IE you have to extract and eval(). In Gecko-browsers, you can create working script-elements using DOM-methods, but it probably isn't worth the bother.


  •  

    Posting Permissions

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