...

Type Mismatch error in Ajax

jennifer_y
07-18-2007, 09:21 AM
I'm in the progress of writing ajax applications. Here is my code

testajax.asp

<input type="text" name="pro_icno2" size="25" maxlength="19" onBlur="showCustomer(document.form, this.value)" disabled />


jsfunction.js

var xmlHttp

function showCustomer(frm,str)
{

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="getcustomer.asp";
url=url+"?q="+str;
alert (url)
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged(frm);
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged(frm)
{
if (xmlHttp.readyState==4)
{
var xmlDoc=xmlHttp.responseXML.documentElement;
//document.getElementById("pro_buyer").innerHTML=xmlDoc.getElementsByTagName("pro_buyer")[0].childNodes[0].nodeValue;
//frm.pro_icno2.disabled=true
frm.pro_buyer.value = xmlDoc.getElementsByTagName("pro_buyer")[0].childNodes[0].nodeValue;
//frm.pro_buyer.value = "Test";

}
}

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;
}



getcustomer.asp
<%
response.expires=-1
response.contenttype="text/xml"

sql="SELECT * FROM prospect WHERE pro_icno="
sql=sql & "'" & request.querystring("q") & "'"

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("../db/prospectivebuyer.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
rs.Open sql, conn

response.write("<?xml version='1.0' encoding='ISO-8859-1'?>")
response.write("<company>")
response.write("<pro_buyer> sql</pro_buyer>")
response.write("</company>")

set rs=nothing
set conn=Nothing

%>

Base on the above source code, i get type mismatch error. Appreciate that someone can guide me thru to solve this problem.

Many Thanks

mcjwb
07-18-2007, 08:22 PM
You need to change this line
xmlHttp.onreadystatechange=stateChanged(frm);
to this:
xmlHttp.onreadystatechange=function(){stateChanged(frm);}

onreadystatechange must always be a function, not a function call as you wrote. If stateChanged(frm) was a function that returned a result, your line above would assign the result to onreadystatechange, which is not what you want to do (unless of course your function returned a function, but we won't go there just now!).

Hope that helps.

jennifer_y
07-19-2007, 07:44 AM
I have try to change the below statement but it return "Syntax Error".

xmlHttp.onreadystatechange=function(){stateChanged(frm);}

mcjwb
07-19-2007, 09:15 AM
That syntax is definately right, you can add a semicolon after the last curly bracket but I doubt it will help in this situation.

I think your reference to the form is wrong here:
<input type="text" name="pro_icno2" size="25" maxlength="19" onBlur="showCustomer(document.form, this.value)" disabled />
I think it should be:
<input type="text" name="pro_icno2" size="25" maxlength="19" onBlur="showCustomer(this.form, this.value)" disabled />



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum