For the past few days I have been refactoring my javascript so it can meet the requirement of working with IE7/8/9.
The code below takes in a filename from a select box and then makes an AJAX call to retrieve an XML file which is then serialized so it can be read.
It works perfectly fine with Firefox, Safari and Chrome.
Code
//this function will take the parameter of filename to then make an AJAX request to the location of that file on a server
function getXML()
{
//get filename from selection box "template_list"
filename = $('#template_list').val();
if (filename != "NULL")
{
//make AJAX request to server for template file
jQuery.ajax
(
{
type : "GET",
url : "xml\/" + filename,
dataType : "xml",
success : xmlToString
}
);
}
}
//loads xmlResponse from AJAX call into a string
function xmlToString(xmlResponse)
{
try
{
//For FF, Opera, Safari
xml = (new XMLSerializer()).serializeToString(xmlResponse);
writeEditDoc(xml);
}
catch (e)
{
// Internet Explorer.
xml = new ActiveXObject("Microsoft.XMLDOM");
xml.loadXML(xmlResponse);
writeEditDoc(xml);
//
}
}
Error
Internet explorer does not like this line of code;
xml.loadXML(xmlResponse);
It throws
SCRIPT13: Type mismatch
What I have tried
- Changing the datatype in the AJAX call from “xml” to “text/xml”
- Using the native .xml() function within JS
I have seen on other posts about doing processing at the server side. However I cannot make any changes to the server as it is without the scope of this project.
EDIT Added XMl
<?xml version="1.0" encoding="UTF-8"?>
<text>${Prologue} </text>
<listOfTags>
<Prologue fixed='n' size='100' type='textBox' value='' ></Prologue>
<Title fixed='n' size='100' type='comboBox' value='' ></Title>
<Surname fixed='n' size='100' type='textBox' value='' ></Surname>
<ProductName fixed='n' size='100' type='textBox' ></ProductName>
<VOLNumber fixed='n' size='100' type='numberBox' ></VOLNumber>
<AppointmentDate fixed='n' size='100' type='datePicker' ></AppointmentDate>
<AppointmentSlot fixed='n' size='100' type='datePicker' ></AppointmentSlot>
<Epilogue fixed='n' size='100' type='textBox' ></Epilogue>
</listOfTags>
<listOfTypes>
<textBox></textBox>
<numberBox></numberBox>
<datePicker></datePicker>
<dropDown></dropDown>
<timeBox></timeBox>
<titleBox></titleBox>
</listOfTypes>
There must be some hack out there for this problem.
Thanks
Fixed myself,
Confirmed working on IE7, IE9 and FF