SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Location
    Colorado
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SP Book: BYO Ajax Web Apps prob

    Hi all,

    I am currently learning AJAX with the Sitepoint book Build Your Own AJAX Web Applications. In case you have the book I am trying to recreate the PHP on pg 105 in ASP. If you don't have the book, it is just a page that mimics a server checking to verify a username and password against the database. Here is what I have:

    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <% 
    ' Set the variables and read in the post variables
    Dim LoginId, Pass, respType, respMsg
    LoginId = Request.Form("LoginId")
    Pass = Request.Form("Pass")
    
    ' This doesn't work either
    'LoginId = Request("LoginId")
    'Pass = Request("Pass")
    
    If LoginId = "username" And Pass = "password" Then
    	respType = "success"
    	respMsg = "appmainpage.asp"
    Else
    	respType = "error"
    	respMsg = "Could not verify your login information"
    	' I changed this line to verify that the username 
                 'and password are not making it to the ASP page
    	'respMsg = "LoginId = " & LoginId & " Pass = " & Pass
    End If
    
    ' This just creates a single entry CSV response that is
    ' handled by the client side JS
    Response.ContentType = "text/plain"
    Response.Write(respType)
    Response.Write(",")
    Response.Write(respMsg)
    %>
    So, one of two things is happening here.

    1. The post data is being sent to the ASP page and I am not reading it in properly (in desperation I even tried QueryString).
    2. I have made a mistake in the JS and the POST data is not making the handoff in the httpXMLRequest. This seems the more likely candidate but remember that I copied this out of a SitePoint book!

    A couple notes on what I have tried.
    1. I added an alert box in the JS at the last second before the request is handed off to the ajax portion of the equation and the variables are properly populated.
    2. The ASP page is definitely being reached because the error message in the Else portion of the If statement gets passed back to the javascript just fine.
    3. You can see in the Else portion (commented out) of the If statement I changed the response to just return the variables. The result was that nothing is being read in to the ASP variables. I tried Request.Form("key") and just Request("key"). No dice.
    4. I tried the form and ASP page alone by commenting out the onload JS code that sets it all in motion. It works fine when there is no JS involved.
    5. As instructed by the book I added,
    Code:
    setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    to the request when the form method is POST. In searching the web I found that this was what tripped up most people.

    That is all I can think of, I know it is a little long but I wanted to give as much detail as possible to avoid wasting people's time. I wanted to first confirm that I have not made an error on the ASP side before posting the JS. For one thing, I am not sure how SitePoint and the author would feel about me posting too much of a book that they sell on the site. If there is a moderator on here who wants to give guidance on that in case it becomes necessary, please do.

    Thanks,
    Swani

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does
    Request.Params.Get("key")
    work?

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Location
    Colorado
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r51 View Post
    Does
    Request.Params.Get("key")
    work?
    I just get an ASP error:

    "Object doesn't support this property or method:"

    I do appreciate the help. Any other thoughts?

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Location
    Colorado
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured it out. It was actually a version control problem. For the record you access the POST variables the same way you normally would but the
    Code:
    setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    has to be set. I thought I had set that but I was working in the wrong document.

    Thanks to anyone who tried to help.


Bookmarks

Posting Permissions

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