SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    May 2003
    Location
    sitepoint
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    return html in ajax

    I'm new to ajax and coded a script that returns the result of a php file. It is fine if it is just text, but if it has html included it prints out the tags instead of treating it like html. How do you treat it as html? I've heard of innerHTML but was told it isn't viewed as standard compliant and some browsers don't even support it.
    Half way to nowhere

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,494
    Mentioned
    164 Post(s)
    Tagged
    1 Thread(s)

    text - html

    Are you using responseText instead of responseXML ?

  3. #3
    SitePoint Addict
    Join Date
    May 2003
    Location
    sitepoint
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh, so responseXML is what to use when you know html will be output?
    Half way to nowhere

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,494
    Mentioned
    164 Post(s)
    Tagged
    1 Thread(s)

    string - DOM

    I think the difference is responseText simply puts the response into a string but responseXML puts the response into a DOM tree. I suppose you could write code to parse the text into mark-up, but it's a lot easier to let the browser do it

  5. #5
    SitePoint Addict
    Join Date
    May 2003
    Location
    sitepoint
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems to come back blank when I use responseXML. Is there a special way that you swap what was in the div with what the response was?
    Half way to nowhere

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,494
    Mentioned
    164 Post(s)
    Tagged
    1 Thread(s)

    working with the DOM

    Don't know what you're trying to do without seeing your code. But from an IBM article by Brett McLaughlin
    HTML Code:
    function updatePage() {
      if (request.readyState == 4) {
        if (request.status == 200) {
          var xmlDoc = request.responseXML;
    
          // work with xmlDoc using the DOM
        }
      }
    }

  7. #7
    SitePoint Addict
    Join Date
    May 2003
    Location
    sitepoint
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, I'll have to search for a good responseXML tutorial, for now I'll just use innerHTML. Thanks for the help!
    Half way to nowhere


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
  •