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
    New Coder
    Join Date
    Feb 2009
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to extract a certain div from responseText

    I am just about javascript newbie, so please bear with me!

    I have the following code which I use to fetch an external file and place it within a div tag on current page.

    At the moment, the code successfully fetches the entire file, but I would like to alter it to fetch only a certain div tag from the file, let's say <div id="mydivtag">

    How can I achieve this?

    Thanks in advance!

    Code:
    mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) {
    			mnmxmlhttp.open ("POST", url, true);
    			mnmxmlhttp.setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
    
    			mnmxmlhttp.send (content);
    			errormatch = new RegExp ("^ERROR:");
    
    			target2 = document.getElementById (divcontent);
    
    			mnmxmlhttp.onreadystatechange = function () {
    				if (mnmxmlhttp.readyState == 4) {
    					mnmString = mnmxmlhttp.responseText;
    
    					if (mnmString.match (errormatch)) {
    						mnmString = mnmString.substring (6, mnmString.length);
    						target = document.getElementById (divcontent);
    						target2.innerHTML = mnmString;
    					} else {						
    						alert(mnmString);						
    						target = document.getElementById (divcontent);
    						target2.innerHTML = mnmString;
    
    
    					}
    				}
    			}
    		}

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    726
    Thanks
    35
    Thanked 132 Times in 123 Posts
    The file has to be fetched, opened and read somewhere.
    If you don't want to do it in the client, you'll have to do it on the server,
    by posting the requirements (the url and and the desired return) to a server script.

  • #3
    New Coder
    Join Date
    Feb 2009
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    great...

    I would rather have it written in the client, and then fetch the div tag from it...

    How can I write responseText to a client?


  •  

    Tags for this Thread

    Posting Permissions

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