ここのプログラマーは、過去に問題を解決するのに非常に役に立ちました。そのため、Ajax について質問することにしました。おそらく簡単な修正ですが、私は Ajax は初めてです。
私がやりたいのは、結果がフレーズ「NOT FOUND」である場合、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>
...