【发布时间】:2012-08-17 16:01:52
【问题描述】:
我用于加载第二个选择框的 ajax 脚本在 firefox 和 chrome 中工作,但内部资源管理器无法处理它。我从我的选择框中调用 onChange 函数,并将选择框中的值赋给该函数。
代码:
function getXMLHTTP()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function getType(categoryName)
{
var strURL="includes/get.php?c="+categoryName+"&sid="+Math.random();
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200)
{document.getElementById('type').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
我的第二个问题是,是否可以在选项标签之间发送文本而不是选项标签中的值?
【问题讨论】:
-
最好使用 AJAX 框架(例如 jQuery)来处理跨浏览器问题。尽量不要重新发明轮子。
-
是的,但它只是这个小脚本而已
标签: javascript html ajax internet-explorer