过去,这里的程序员在为我解决问题方面非常有帮助,所以我想我会问一个 Ajax 问题。这可能是一个简单的修复,但我是 Ajax 的新手。
如果结果是短语“未找到”,我想做的是将 responseText 的样式更改为红色。否则文本将是黑色的。这是我正在使用的脚本:
<script type="text/javascript">
<!--
function newXMLHttpRequest()
{
var xmlreq = false;
if (window.XMLHttpRequest)
{
xmlreq = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
try
{
xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e2)
{
alert("Error: Unable to create an XMLHttpRequest.");
}
}
return xmlreq;
}
function getLocation(location)
{
var getLocation= newXMLHttpRequest(); // sending request
getLocation.open("GET", "/PP?PAGE=GETLOCATIONNAME&ROUTINGNUM=" + location, false);
getLocation.send(null); // getting location
document.getElementById("location_div").innerHTML = getLocation.responseText;
}
//-->
</script>
这是HTML:
...
<table>
<tr>
<td class="ajax_msg">
<div id="location_div"><div>
</td>
</tr>
</table>
...