Results 1 to 2 of 2

Thread: Loading HTML and then adding to that new content

  1. #1
    Join Date
    Jun 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Loading HTML and then adding to that new content

    Hey

    I have a script which is meant to add to the div, but i don't want to add the content via the "call_back" div otherwise im limited on the dynamic possibilities. So i'm wondering how i do a request then "continue" from that request on wards if that makes sense... (i added comment where i refer to):


    Code:
    function call_back(result,div_id){
    	document.getElementById(div_id).innerHTML = result;
    }
    
    function caller(url,cfunc)
    {
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=cfunc;
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
    }
    
    
    function call_file(url,div_id){
    	caller(url,function(){
    		if (xmlhttp.readyState==4 && xmlhttp.status==200){
    			call_back(xmlhttp.responseText,div_id);
    		}
    	});
    }
    
    window.onload = function() {  
      
      file = 'test.html';
      div_id = 'test';
      result = call_file(file,div_id);
      call_file(file,div_id);
      //something here to check "call_file" completed successfully then continue with code below
      document.getElementById('test2').innerHTML = 'Hi'; //currently it says innerHTML is not found so i need to fix that
      
    };
    Any ideas on how to do this ?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The only way to know there has been success is here:

    Code:
    function call_file(url,div_id){
    	caller(url,function(){
    		if (xmlhttp.readyState==4 && xmlhttp.status==200){
    			call_back(xmlhttp.responseText,div_id);
    		}
    	});
    }
    And of course anything in call_back() would only be done if there were success. You could pass in another argument telling it what to do. But in order to execute only upon success, it will have to be executed one of those two places, or somewhere one of them points to.

    Also you have two id's, 'test' and 'test2'. Is there an actual test2 element? If not, that's why you're getting an error. If you do have a test2 element, it should work. But there could always be some other problem that's not readily apparent from the code you're showing. Do you actually want "Hi" or whatever to appear in a separate element?

    If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. swf/xml not loading in HTML :(
    By great_dindi in forum Flash
    Replies: 0
    Last Post: 03-31-2011, 07:12 PM
  2. loading html in DIV tag
    By ravimmrk in forum JavaScript
    Replies: 6
    Last Post: 05-28-2008, 07:33 PM
  3. Adding HTML to My PHP Page
    By tomyknoker in forum PHP
    Replies: 14
    Last Post: 03-15-2007, 05:47 PM
  4. Loading HTML
    By Cheng in forum HTML
    Replies: 6
    Last Post: 08-09-2006, 02:08 AM
  5. adding to html page
    By serothis in forum JavaScript
    Replies: 1
    Last Post: 06-20-2006, 08:51 PM

Bookmarks

Posting Permissions

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