Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Type Mismatch error in Ajax

    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

  • #2
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    You need to change this line
    Code:
    xmlHttp.onreadystatechange=stateChanged(frm);
    to this:
    Code:
    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.

  • #3
    New Coder
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have try to change the below statement but it return "Syntax Error".

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

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    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:
    Code:
    <input type="text" name="pro_icno2" size="25" maxlength="19" onBlur="showCustomer(document.form, this.value)" disabled />
    I think it should be:
    Code:
    <input type="text" name="pro_icno2" size="25" maxlength="19" onBlur="showCustomer(this.form, this.value)" disabled />


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •