Hi i am new to AJAX but i havejust managed to write one of my first basic scripts.
What it does is takes all the news items out of a database and lists them as links. When you click a link i want all of the data that is linked to that news item to display underneath.
Now i have got this to work except it will not work in Firefox, all other browsers it is fine.
Below is the code i have written,
<script>
<!--
var xmlHttp = XMLHttpRequest();
function submitSelection() {
if (event.keyCode==13) {
alert(event.keyCode);
}
}
function showResult(str) {
if (event.keyCode==40) {
document.getElementById("news_details").focus();
} else {
if (str.length==0) {
document.getElementById("news_details").innerHTML="";
document.getElementById("news_details").style.border="0px";
return;
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null) {
alert ("Browser does not support HTTP Request");
return;
}
var url="ajax_tom_server_script.asp";
url=url+"?news_id="+str;
xmlHttp.onreadystatechange=stateChanged ;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
}
function stateChanged() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
document.getElementById("news_details").innerHTML=xmlHttp.responseText;
// document.getElementById("customer_search_results").focus();
}
}
function GetXmlHttpObject() {
var xmlHttp=null;
if (window.XMLHttpRequest){
try{
xmlHttp = new XMLHttpRequest();
}catch (e){
xmlHttp = false;
}
}else if (window.createRequest){
try{
xmlHttp = new window.createRequest();
}catch (e){
xmlHttp = false;
}
}else if (window.ActiveXObject){
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e){
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
xmlHttp = false;
}
}
}
return xmlHttp;
}
-->
</script>
<%
Set rs_list = server.CreateObject("ADODB.Recordset")
sSQL = "SELECT * FROM news WHERE deleted <> 1"
Set rs_list = conn_tom.Execute(sSQL)
if rs_list.eof then
response.Write("No News")
else
do while not rs_list.eof
id = rs_list.fields("news_id")
response.Write("<a href='#' onclick='javascript:showResult(" & id & "); return false'>" & rs_list.fields("news_title") & "</a><br />")
rs_list.movenext
loop
end if
%>
<div id="customers_search">
<div id="news_details"></div>
</div>
Could anyone please help. Thanks in advance.