Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

AJAX Code nightmare

Options
  • 29-10-2007 9:21pm
    #1
    Registered Users Posts: 269 ✭✭


    Could someone please tell me why the following ajax is not working. I have it running on my IIS on my PC:

    Html page:

    <html>
    <head>
    <script src="selectcustomer.js"></script>
    </head>

    <body>

    <form>
    Select a Customer:
    <select name="customers" onchange="showCustomer(this.value)">
    <option value="ALFKI">Alfreds Futterkiste
    <option value="NORTS ">North/South
    <option value="WOLZA">Wolski Zajazd
    </select>
    </form>

    <p>
    <div id="txtHint"><b>Customer info will be listed here.</b></div>
    </p>

    </body>
    </html>

    ASP Page

    <%
    response.expires=-1
    sql="SELECT * FROM CUSTOMERS WHERE CUSTOMERID="
    sql=sql & "'" & request.querystring("q") & "'"

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

    response.write("<table>")
    do until rs.EOF
    for each x in rs.Fields
    response.write("<tr><td><b>" & x.name & "</b></td>")
    response.write("<td>" & x.value & "</td></tr>")
    next
    rs.MoveNext
    loop

    response.write("</table>")
    %>

    Javascript

    var xmlHttp

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

    function stateChanged()
    {
    if (xmlHttp.readyState==4)
    {
    document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
    }
    }

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


«1

Comments

  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Download fiddler and check to see if the AJAX is firing or not.

    Also add the following code to your javascript
    if (xmlhttp.status==200)
        {
        document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
    
        }
      else
        {
        alert("Problem retrieving XML data"),
        }
    
    


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Also can you check if you can run the ASP file and if its working correctly, it may be returning incorrect information


  • Registered Users Posts: 269 ✭✭cyberwit


    Microsoft Script Debugger is telling me that "a Runtime Error has occurred do i wish to debug? Line: 15 Error: Access denied
    Line 15 selectcustomer.js : xmlHttp.open("GET","getcustomer.asp",true);

    Firefox shows me the following (my asp code):

    <% response.expires=-1 sql="SELECT * FROM CUSTOMERS WHERE CUSTOMERID=" sql=sql & "'" & request.querystring("q") & "'" set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("db/northwind.mdb")) set rs = Server.CreateObject("ADODB.recordset") rs.Open sql, conn response.write("
    ") do until rs.EOF for each x in rs.Fields response.write("" & x.name & "") response.write(" " & x.value & "
    ") next rs.MoveNext loop response.write("
    ") %>


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Right

    Run the ASP file with a parameter q .. verify that in fact it returns information..

    Is the DB open and also have you given full permissions on the folder in windows to the IUSR account?


  • Registered Users Posts: 269 ✭✭cyberwit


    Ginger wrote: »
    Right

    Run the ASP file with a parameter q .. verify that in fact it returns information..

    Is the DB open and also have you given full permissions on the folder in windows to the IUSR account?


    I tested the asp page with
    response.write("Hello World!") and it works.

    I am not sure what you are taking about with regards the IUSER Account, dont i need to setup the database up in such a way as to be able to access it using the web or visual basic or ASP i just cant remember


  • Advertisement
  • Registered Users Posts: 2,931 ✭✭✭Ginger


    No no:.. thats not what I asked.. I asked you to test your current page and pass in a correct value for q so that it will return the table... Access is notorious when doing web programming for locking and returning errors it should never be used.. use MSSQL 2005 Express edition if you can!


  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    customer id is a number not text so do not encapsulate in quotes - check your sql statement

    -RD


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Unless customer ID is a string :)


  • Registered Users Posts: 269 ✭✭cyberwit


    I am just using Access in this test example i would use oracle in the finished product. The example i am runnning is the one on the W3C school website


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Again can you do something like this

    http://yoursite/page.asp?q=1

    I want to see if its returning a table or not..


  • Advertisement
  • Registered Users Posts: 269 ✭✭cyberwit


    Ginger wrote: »
    Again can you do something like this

    http://yoursite/page.asp?q=1

    I want to see if its returning a table or not..

    Sorry i taught i had already said it does not return a table only the asp code


  • Registered Users Posts: 269 ✭✭cyberwit


    I am not using visual webdeveloper or dreamweaver just notepad my priority is gettin the ajax working not really concerned with design issues


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Ok, if its returning ASP, then your ASP is incorrect and has an error...

    What version of Windows are you using?


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Actually is it returning the ASP code unexecuted as text or something or am I misreading that


  • Moderators, Science, Health & Environment Moderators Posts: 8,950 Mod ✭✭✭✭mewso


    You are building your url with querystring then not using it:-

    var url="getcustomer.asp";
    url=url+"?q="+str;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET","getcustomer.asp",true);
    xmlHttp.send(null);

    change to

    xmlHttp.open("GET",url,true);

    Also your first line in the asp file should probably set the contentype:-

    response.contentype = "text/plain"


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Give that man a biscuit! Good eyes


  • Registered Users Posts: 269 ✭✭cyberwit


    xmlHttp.open("GET",url,true);

    I had that originally but did not work neither does the new way either.

    Yes all the ASP file is showing is ASP code unexecuted as text


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    what version of windows then... Sounds like ASP.DLL aint working or the .ASP MIME type is being parsed as text


  • Registered Users Posts: 269 ✭✭cyberwit


    Windows XP Professional. I installed the IIS on my computer and it runs previous websites i have produced more or less originally when i tryed to use it i was asked for a username and passwork but found out how to use it.


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Can you create a page called test.asp and put the following in

    <%=Now()%>

    that should just show the current time.

    If it doesnt then we just need to sort out the ASP stuff for you


  • Advertisement
  • Registered Users Posts: 269 ✭✭cyberwit


    Nope not working again just showing asp code <%=Now()%>

    I have used the IIS server in my college fine its just this one installed on my pc is driving me mad


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Is ASP installed I wonder...

    It should work by default. By any chance do you have Norton AV installed or something that could be knocking it out.

    Can you do the following

    Open the IIS manager

    Select Default Web Site and bring up the Properties dialog box.

    Select the HTTP Headers tab.

    Under MIME Map, click the File Types tab

    Check if ASP is there and if it is, is all verbs going through ASP.dll???


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Also check the following in your event viewer

    MSDTC errors (4427,4691,4135 are common error events for this)
    W3SVC Event 36 "The server failed to load application '/LM/W3SVC/1/ROOT/'. The error was 'Class not registered"

    Also need to you to turn off friendly error messages in IE

    Also have a look at the following

    http://support.microsoft.com/default.aspx?scid=kb;en-us;309051#2


  • Registered Users Posts: 269 ✭✭cyberwit


    Ginger wrote: »
    Is ASP installed I wonder...

    It should work by default. By any chance do you have Norton AV installed or something that could be knocking it out.

    Can you do the following

    Open the IIS manager

    Select Default Web Site and bring up the Properties dialog box.

    Select the HTTP Headers tab.

    Under MIME Map, click the File Types tab

    Check if ASP is there and if it is, is all verbs going through ASP.dll???


    Thre is no registered file types it's empty


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Could be in there somewhere.. sorry mate I doing this from memory, i dont have IIS installed on this PC


  • Registered Users Posts: 269 ✭✭cyberwit


    Don't worry about it i am just greatful for the help


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Please also have a look at this http://brooksyounce.tripod.com/XpAspFix.htm


  • Registered Users Posts: 269 ✭✭cyberwit


    Can i use anything else instead of IIS now i dont want to install a seperate server just some application maybe that will enable me to run the site


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    IIS natively runs ASP, just something weird with your installation


  • Advertisement
  • Moderators, Science, Health & Environment Moderators Posts: 8,950 Mod ✭✭✭✭mewso


    Ginger wrote: »
    Could be in there somewhere.. sorry mate I doing this from memory, i dont have IIS installed on this PC

    Just checked there - Home Directory tab - click configuration and you will see a list of file extensions. .asp should be linked to asp.dll.


Advertisement