AJAX with ASP - responseText works, responseXML doesn't


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: AJAX with ASP - responseText works, responseXML doesn't

  1. #1
    Join Date
    Oct 2006
    Posts
    4

    AJAX with ASP - responseText works, responseXML doesn't

    Hi all,
    just starting with AJAX and come up against the following problem. I created a simple script reading a plain XML file and it worked fine.

    However when I reproduced the same XML using ASP, whilst responseText reproduced it fine, a reference to the XML DOM using reponseXML didn't seem to have any content.

    As far as I know the server is .NET

    Can anyone point me in the right direction?

    many thanks

  2. #2
    Join Date
    Oct 2006
    Posts
    4
    Sorted it. I just needed to put

    <%
    response.ContentType = "text/xml"
    %>

    in my asp file. Otherwise the response header is set to Content-type: "text/html" which I guess is what the problem was.

  3. #3
    Join Date
    Mar 2006
    Posts
    100
    WORD OF WARNING
    IE does not support responseXML!!!!!!!!!!

    I had a similar issue with IE you actually have to enter the information into a div tag use DOM on the div tag and then delete the info.

    Here is an example I did

    //function responseReports()
    //{
    // try
    // {
    // if (xmlHttpForms.readyState==4 || xmlHttpForms.readyState=="complete")
    // {
    // if (!finished)
    // {
    // var xmlDoc;
    // alert(xmlHttpForms.responseText);
    // if (window.ActiveXObject)
    // {
    // xmlDoc = convertMS(xmlHttpForms.responseText);
    // alert("done");
    // }
    // else if (document.implementation && document.implementation.createDocument)
    // {
    // //alert("Other Browser");
    // xmlDoc = xmlHttpForms.responseXML;
    // //In case to be the internet explorer
    // }
    //
    // else
    // {
    // //If the browser doesnt support xml
    // alert('Your browser can\'t handle this script');
    // return;
    // }
    // var table = document.getElementById("tbSelReports");
    // var divTag = handleReportData(xmlDoc);
    // alert("done");
    // table.appendChild(divTag);
    // finished=true;
    // alert("done");
    // }
    // }
    // }
    // catch(e)
    // {alert(e.message);}
    //}

    function convertMS(responseTxt)
    {
    alert(responseTxt);
    try
    {
    //Create a xml tag in run time
    var testandoAppend = document.createElement('xml');

    //Put the requester.responseText in the innerHTML of the xml tag
    testandoAppend.setAttribute('innerHTML',responseTxt);
    //Set the xml tag's id to _formjAjaxRetornoXML
    testandoAppend.setAttribute('id','_formjAjaxRetornoXML');
    //Add the created tag to the page context
    document.body.appendChild(testandoAppend);

    //Now we can get the xml tag and put it on a var
    xmlDoc = document.getElementById('_formjAjaxRetornoXML');
    //So we have a valid xml we can remove the xml tag
    document.body.removeChild(document.getElementById('_formjAjaxRetornoXML'));
    return xmlDoc;
    }
    catch(e){alert(e.message);}
    }

Similar Threads

  1. server question... asp solution asap
    By bushkri in forum ASP.NET
    Replies: 2
    Last Post: 12-14-2001, 10:11 AM
  2. Replies: 0
    Last Post: 09-06-2001, 10:37 AM
  3. ASP, ADO and Personal Web Server
    By Paul in forum ASP.NET
    Replies: 0
    Last Post: 08-06-2001, 12:11 AM
  4. Replies: 1
    Last Post: 04-20-2001, 03:46 PM
  5. NT priveleges from an ASP program
    By Matthew Solnit in forum authorevents.appleman
    Replies: 1
    Last Post: 04-11-2000, 05:39 PM

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center