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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

AJAX Code nightmare

  • 29-10-2007 8:21pm
    #1
    Registered Users, Registered Users 2 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;
    }


Comments

  • Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Unless customer ID is a string :)


  • Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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: 9,035 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, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Give that man a biscuit! Good eyes


  • Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 269 ✭✭cyberwit


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


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


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


  • Registered Users, Registered Users 2 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, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    IIS natively runs ASP, just something weird with your installation


  • Advertisement
  • Moderators, Science, Health & Environment Moderators Posts: 9,035 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.


  • Registered Users, Registered Users 2 Posts: 269 ✭✭cyberwit


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

    The asp.dll file is there


  • Registered Users, Registered Users 2 Posts: 378 ✭✭sicruise


    Lads... this just sounds like a permissions issue...


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


    Nah permissions would give a 403 error or similar types of errors not show the ASP code in the browser..


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


    1. Do you have Anti virus software running (with script blocking or something similar)
    2. Is ASP.DLL registered
    3. Is it being used for all verbs for the ASP file types

    Did you check out those links i posted earlier


  • Closed Accounts Posts: 345 ✭✭FindingNemo


    have you checked your .net configuration. go into admin tools, .net configuration, list the assemblies and make sure AJAX is registered ?


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


    Its classic ASP not .NET


  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    back up a bit
    try http://yourcomputername

    if IIS is installed correctly the you will get a "Welcome to IIS" page.

    if you don't get this reinstall IIS.

    If you do get this create a simple page with the code below call it test.asp
    and see can you navigate to the page. If you can you should see hello in the middle of page. At this point you know IIS is working and ASP pages are processed correctly.

    [PHP]<%
    Response.Write ("HELLO")
    %>
    [/PHP]

    next step is to test you asp page
    so navigate it to passing in any parameters
    and see what happends
    if it works great you have a problem calling it from JScript
    if it doesn;t you should get an error

    post the error here


  • Moderators, Science, Health & Environment Moderators Posts: 9,035 Mod ✭✭✭✭mewso


    I think we've been through all that. It does not seem to be parsing the asp script. Read above and you will see this. A re-install of iis might be in order.


  • Registered Users, Registered Users 2 Posts: 269 ✭✭cyberwit


    I reinstalled IIS and remove security related functions in the Directory Security because i could not run iisstart.asp because it was asking me for a password and username now it does not it produces an error page - The page cannot be displayed HTTP 500.100 - Internal Server Error - ASP error
    Internet Information Services

    Looked at the resolution to the problem on microsoft website confused same error message when i try to run my test website asp not, a html webpage is showing fine


  • Registered Users, Registered Users 2 Posts: 269 ✭✭cyberwit


    The page cannot be displayed
    There is a problem with the page you are trying to reach and it cannot be displayed.


    Please try the following:

    Click the Refresh button, or try again later.

    Open the localhost home page, and then look for links to the information you want.
    HTTP 500.100 - Internal Server Error - ASP error
    Internet Information Services


    Technical Information (for support personnel)

    Error Type:
    Microsoft VBScript runtime (0x800A0046)
    Permission denied: 'GetObject'
    /localstart.asp, line 40


    Browser Type:
    Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.0.04506.30)

    Page:
    GET /localstart.asp

    Time:
    Wednesday, October 31, 2007, 9:14:00 PM


    More information:
    Microsoft Support


  • Advertisement
  • Closed Accounts Posts: 345 ✭✭FindingNemo




  • Registered Users, Registered Users 2 Posts: 269 ✭✭cyberwit


    I ran the site on the IIS server in college a works perfectly I want to thank all those of you for your very much appreciated assistance.


Advertisement