www.webdeveloper.com
Results 1 to 2 of 2

Thread: Checking for XML or HTML

  1. #1
    Join Date
    Jul 2007
    Posts
    183

    Checking for XML or HTML

    Hi Guys

    If I send off an ajax post/get request and the server returns some data, is there any way I can check what type of data has been recieved (XML or HTML)? and then use the appropriate return call (i.e. responseText or responseXML) ?

  2. #2
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,755
    Say the variable that holds the XML HTTP request object is called xhr.
    Code:
    if (xhr.responseXML) {
      // Is XML
    } else {
      // Is not XML
    }
    If the response is valid XML, the responseXML property will not be null. If the response contains invalid XML, the responseXML property will be null or undefined -- some sort of value that evaluates to false.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles