TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   AJAX does not work (http://forums.techarena.in/software-development/1103368.htm)

Gap meer 14-01-2009 02:20 PM

AJAX does not work
 
I was going to test this with AJAX and found a complete written solution to the network. A solution that at first look would solve my problems.

After a month or so I tested it locally on my computer (XP with IIS ).... it did not work. I uploaded the same patterns on a webserver .... did not work either. Are any of the server or in my computer in the form of additional or setting to XML / AJAX to work ?????? Or is it something I am doing wrong? Is not quite familiar in this with AJAX ... yet.

The first page looks like this:
Code:

<html> <head> <script language="javascript"> var xmlHttpfunction showCustomer(str) { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="getdatum_xml.asp"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); }function stateChanged() { if (xmlHttp.readyState==4) { var xmlDoc=xmlHttp.responseXML.documentElement; document.getElementById("Lopp").innerHTML= xmlDoc.getElementsByTagName("Lopp")[0].childNodes[0].nodeVal
 ue; document.getElementById("Datum").innerHTML= xmlDoc.getElementsByTagName("Datum")[0].childNodes[0].nodeVa
 lue; } } function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } </script> </head> <body> <% Set Connection = Server.CreateObject("ADODB.Connection") Connection.Open "driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.mappath("DATABAS.mdb") SQLStmt = "SELECT * FROM TABELL1 ORDER BY Datum" Set RS = Connection.Execute(SQLStmt) %> <form action=""> V?lj datum: <select name="customers" onchange="showCustomer(this.value)"> <option value="">--- V?lj datum ---</option> <%Do Until RS.EOF%> <option value="<%=RS("Datum")%>"><%=RS("Datum")%><
 /option> <% RS.MoveNext Loop RS.Close Connection.Close %> </select> </form> <b> <span id="companyname"></span></b><br /> <span id="contactname"></span><br /> </html>

getdatum_xml.asp looks like this:
Code:

<% response.expires=-1 response.contenttype="text/xml"sql="SELECT * FROM TABELL2 " sql=sql & " WHERE Datum='"&request.querystring("q")&"'" on error resume next set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("DATABAS.mdb")) set rs=Server.CreateObject("ADODB.recordset") rs.Open sql, connif err <> 0 then response.write(err.description) set rs=nothing set conn=nothing else response.write("<?xml version='1.0' encoding='ISO-8859-1'?>") response.write("<company>") response.write("<Datum>" &rs.fields("Datum")& "</Datum>") response.write("<Lopp>" &rs.fields("Lopp")& "</Lopp>") response.write("</company>") end if on error goto 0 %>
What is wrong? Is it the server or the code?

Katty 14-01-2009 02:23 PM

Re: AJAX does not work
 
The easiest way is if you are troubleshooting.
Run getdatum_xml.asp alone. Does it go to the JavaScript.
See if you can answer when the other file called by printing a alert.

Troubleshooting 101, simply.

Among others, I found a flaw in this line:
Code:

s.Open sql, connif err <> 0 then
You know what to do ;)

Gap meer 14-01-2009 02:24 PM

Re: AJAX does not work
 
Have run getdatum_xml.asp alone, and it seems (in my eyes anyway) that that part works. What I am less sure of is whether JavaScript faults .. ie if the sending of value and if it takes the results from the ASP page.

Where in the script, it is appropriate to add an alert?

Code:

<html> <head> <script language="javascript"> var xmlHttpfunction showDatum(str) { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="getlopp.asp"; url=url+"?Datum="+str; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); }function stateChanged() { if (xmlHttp.readyState==4) { var xmlDoc=xmlHttp.responseXML.documentElement; document.getElementById("Loppen").innerHTML= xmlDoc.getElementsByTagName("Lopp")[0].childNodes[0].nodeVal
 ue; document.getElementById("Datumen").innerHTML= xmlDoc.getElementsByTagName("Datum")[0].childNodes[0].nodeVa
 lue; } } function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } </script> </head> <body> <% Set Connection = Server.CreateObject("ADODB.Connection") Connection.Open "driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.mappath("..\..\Db\DATABAS.mdb") SQLStmt = "SELECT * FROM TABELL1 ORDER BY Datum" Set RS = Connection.Execute(SQLStmt) %> <form action=""> V?lj datum: <select name="Datum" onchange="showDatum(this.value)"> <option value="">--- V?lj datum ---</option> <%Do Until RS.EOF%> <option value="<%=RS("Datum")%>"><%=RS("Datum")%><
 /option> <% RS.MoveNext Loop RS.Close Connection.Close %> </select> </form> <HR> <span id="Loppen"></span></b><br /> <span id="Datumen"></span><br /> </html>


Katty 14-01-2009 02:27 PM

Re: AJAX does not work
 
I can now find more serious errors in the javascript code.
There are line breaks, which makes available to it. Look like the javascript errors that arise. If you get no errors, you have probably just not set in the browser that will warn the javascript errors.


was xmlHttpfunction showdate(str) <--- FEEEL


was XMLHTTP; //new line here
function show Date (str)

Gap meer 14-01-2009 02:28 PM

Re: AJAX does not work
 
Ahhhh, you are an angel. Now came the JavaScript running anyway. Fixed now grappling I followed the wrong .... I will return soon :)


All times are GMT +5.5. The time now is 08:56 PM.