-
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
-
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.
-
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
-
By bushkri in forum ASP.NET
Replies: 2
Last Post: 12-14-2001, 10:11 AM
-
Replies: 0
Last Post: 09-06-2001, 09:37 AM
-
Replies: 0
Last Post: 08-05-2001, 11:11 PM
-
By Martin McManus in forum ASP.NET
Replies: 1
Last Post: 04-20-2001, 02:46 PM
-
By Matthew Solnit in forum authorevents.appleman
Replies: 1
Last Post: 04-11-2000, 04: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
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|