出于某种原因,以下代码适用于 Internet Explorer,但不适用于 Chrome 或 Firefox。在此浏览器中,我收到:
“无法检索滑块数据。”
警报。
我很想得到一些帮助。
谢谢。
这是我的 JavaScript 代码:
<script>
if (navigator.appName == "Microsoft Internet Explorer")
{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
request = new XMLHttpRequest();
}
if (request == null)
alert ("Your browser doesn't support XMLHttpRequest");
function getSelectedText(elementId)
{
var elt = document.getElementById(elementId);
if (elt.selectedIndex == -1)
return null;
return elt.options[elt.selectedIndex].value;
}
function sendRequest()
{
debugger;
var type = getSelectedText('dropdown');
//alert("The chosen type: "+type);
var url = 'https://tomcat-emildesign.rhcloud.com/coupons/Client/serveranswer.jsp?type=' + type;
request.open("GET", url, true);
request.onreadystatechange= processRequest;
request.send(null);
}
function processRequest()
{
if (request.readyState == 4)
{
if (request.status == 200)
{
parseMessage();
}
else
{
alert ( "Not able to retrieve sliders data." );
}
}
}
function parseMessage()
{
// Assign the XML file to a var variable.
var doc = request.responseXML;
var pending, hires, rejected;
if(navigator.appName == "Microsoft Internet Explorer")
{
pending = doc.documentElement.getElementsByTagName('pending').item(0).text;
hires = doc.documentElement.getElementsByTagName('hires').item(0).text;
rejected = doc.documentElement.getElementsByTagName('rejected').item(0).text;
}
else
{
pending = doc.documentElement.getElementsByTagName('pending')[0].textContent;
hires = doc.documentElement.getElementsByTagName('hires')[0].textContent;
rejected = doc.documentElement.getElementsByTagName('rejected')[0].textContent;
}
alert("values:" + pending + "," + hires + "," + rejected);
}