Exploring the Interplay of Classic ASP and AJAX Variables References

When the page loads, I check for an empty session variable. If it is empty, I trigger an AJAX function to include a hidden login form with ASP script that becomes visible through JavaScript. This part of the process works smoothly.

Upon submitting the form, I verify if the password field is empty, incorrect, or correct. The validation process functions correctly in this stage as well.

However, despite successfully checking these conditions, attempts to hide the overlay form using either JavaScript or setting VBScript conditional variables prove ineffective.

It seems that clearing the cache by refreshing the page or navigating away after submitting the form removes the overlay, confirming that the session variables have indeed been set.

There are two main issues at hand:

  1. Why doesn't the ASP page refresh every time it is invoked? I test this by toggling a visible text line, saving the form, and then triggering the submit button to invoke the form.

  2. Why do the embedded JS or ASP script variables fail to take effect? I examine the JS code with a console.log to troubleshoot this matter.

Firstly, let's look at the JS code:

function checkLogin() {
  var password = document.getElementById("password").value;
  var userID = document.getElementById("UserID").value;
  if (password != null) {
    if (window.XMLHttpRequest) {
      var xmlhttp = new XMLHttpRequest();
    } else {
      var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
      if (this.readyState == 4 && this.status == 200) {
        console.log("xxx: " + document.getElementById("session").value);

        if (document.getElementById("session").value == true) {
          document.getElementById("overlay").style.display = "none";
          document.getElementById("login").style.display = "none";
        }
        document.getElementById("password").innerHTML = password;
      }
    };
    xmlhttp.open("GET", "includes/checkpw.asp?u=" + userID + "&p=" + password);
    xmlhttp.send();
  }
}

Next, let's observe the content of the include file:

<%
    response.expires = -1
    
    set conn = server.createobject("ADODB.connection")%>
    <!--- #include virtual=/includes/connpath.asp -->
    
    <%querySQL = "qryselUser"
    set recset = conn.execute(querySQL)
    if not recset.bof and not recset.eof then
        arrUser = recset.getrows
        countUser = ubound(arrUser,2)
    end if%>
    
    <%if Request.Form("formbtn") = "Cancel" then
        Session.Abandon
        conn.close()
        set conn = nothing
        Response.Redirect "default.asp"
    end if
    
    querySQL = "qryselUser"
    set recset = conn.execute(querySQL)
    if not recset.bof and not recset.eof then
        arrUser = recset.getrows
        countUser = ubound(arrUser,2)
    end if%>
    
    <%UserID = cint(request.querystring("u"))
    password = request.querystring("p")
    if password <> "" then
        querySQL = "qryselLogin'" & UserID & "'"
        set recset = conn.execute(querySQL)
        arrUser = recset.getrows
        recset.close
        set recset = nothing
        if UserID = arrUser(0,0) and password = arrUser(2,0) then
            session("id") = arrUser(0,0)
            session("level") = arrUser(3,0)
            session("lock") = arrUser(4,0)
            sessiontrue = true
            conn.close()
            set conn = nothing%>
        <%else
            userError = "Either Username or Password is incorrect"%>
            <script>console.log("Error")</script>
            <%querySQL = "qryselUser"
            set recset = conn.execute(querySQL)
            arrUser = recset.getrows
            countUser = ubound(arrUser,2)   
            recset.close
            set recset = nothing
        end if
    end if%>
    <!--- Form contents --->
 

I am facing some challenges in this process and would appreciate any guidance or assistance in resolving these issues effectively.

Answer №1

Ensure each query is distinct by including a date and time stamp.

xmlhttp.open("GET","includes/checkpw.asp?u="+userID+"&p="+password+new Date());

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Obtain a string in JSON format upon clicking in Angular 2

I am working on extracting the title from a json response using a click event. Currently, I can retrieve all the titles when the button is clicked, but I am looking for a way to obtain a specific title based on the button or a href that the user has clicke ...

Tips for testing components with React JS using jest and enzyme

Attempting to perform a unit test on the code snippet below: handleChange = (e) => { let localState = Object.assign({}, this.state) localState[e.target.name] = e.target.value this.setState(localState) this.props.addMetaInformation(localState) } } I&a ...

Utilize webpack to import functions from separate files

I am looking to streamline the process of importing and using functions from a different file. Ideally, I would like to simply call these functions by their name without any extra prefixes or naming conventions. However, I am aware that using eval() can po ...

Eslint in Gulp can't locate my .eslintrc configuration file

My gulp-eslint is unable to locate my .eslintrc file. I've set up a lint task as follows: gulp.task('lint', function () { gulp.src(['src/**/*.js', 'src/**/*.jsx']) .pipe(eslint()) .pipe(eslint.format()); }) The t ...

Aborting ASP.net page's SQL query

For the past week, I've been working on solving a problem that involves creating 2 buttons - "Execute" and "Cancel". Clicking "Execute" triggers a lengthy SQL query, while clicking "Cancel" should stop the query. The issue arises when two ajax queries ...

Dynamically modifying the styling of elements within an iframe

In my current project, I encountered a challenge with changing the background color to black and the body text color to white within an iframe. Additionally, all elements that are originally styled with black in an external stylesheet also need to be chang ...

Determining the query count in a MongoDB collection using Node.js

Exploring the world of MongoDb, I have embarked on a project to create a small phonebook application. This application allows users to add and remove entries with a name and phone number. While I have successfully implemented the functionality to add and d ...

differences between using form's get method and sending an angular $http.get request

When trying to make a GET request to a specific URL from my Angular frontend to an ExpressJS backend, I encountered some interesting behavior. In the frontend code snippet below: <li> <a ng-click="givequiz()">GiveQuiz</a> </l ...

"Enhance your website with Express.js and eliminate the need for full

As I continue to work on my website, I am faced with a challenge. While the page is not overly large, I want to ensure that when navigating to different tabs in the navbar, the entire site does not have to reload each time. Currently, I am using express.js ...

The show/hide jquery function is functioning perfectly on desktop devices, but issues arise on mobile devices where the divs overlap each other when using the show() method

I need a way to toggle input text boxes based on selection using a select box This is the HTML code snippet: <div class="row"> <div class="form-group"> <div class="col-sm-1 label2"> <label class="control-label ...

What is the reason for the index.html file not connecting to the local .css files and .js file?

I'm currently using node.js to send an .html file that includes the following tags: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="description" content="This is my personal profile website" /> <link r ...

What is the best way to incorporate a string value from an external file into a variable in TypeScript without compromising the integrity of special characters?

I am encountering an issue with importing a variable from a separate file .ts that contains special characters, such as accents used in languages like French and Spanish. The problem I am facing is that when I require the file, the special characters are ...

Invoke the ng-click function within the ng-change function

Just starting out with angularjs and I have a question. I am currently using single select and I want to retrieve the value selected and based on that value, perform an action. For example, if the value is "DELETE" then I would like to trigger the ng-clic ...

creating sleek animations with Pixi.js for circular shapes

Is it possible to create smooth animations on circles or sprites similar to D3.js hits in Leaflet? https://drive.google.com/file/d/10d5L_zR-MyQf1H9CLDg1wKcvnPQd5mvW/view?usp=sharing While D3 works well with circles, the browser freezes. I am new to Pixi. ...

Using jQuery to deactivate the submit button when a field is empty or a checkbox is left unchecked

Today is my first attempt at using jQuery, and I could really use some assistance as I'm struggling to achieve the desired outcome. I'm dealing with a table of documents, each containing a checkbox for selection purposes. Additionally, there&apo ...

Using Firebase with Angular 4 to fetch data from the database and show it in the browser

Currently diving into Angular 4 and utilizing Firebase database, but feeling a bit lost on how to showcase objects on my application's browser. I'm looking to extract user data and present it beautifully for the end-user. import { Component, OnI ...

Using Ajax with aspnet mvc 5 to enhance Partial Views

I have a list of items in my shared HTML that are identified by IDs as names. I attempted to update a specific div by passing the ID through AJAX, but unfortunately, the div does not get updated. 1 Here is the list of companies : <div class="dropdown- ...

Dealing with Errors When Working with Angular Promises

Currently, I am in the process of mastering promises within Angular. In my code snippet, I have two "GET" requests that I need to execute sequentially. Everything is functioning properly, but I'm unsure about how to handle errors in this scenario. If ...

Tips on waiting for a screenshot of a webpage to be captured using Selenium and PhantomJS in Python 3

Want to capture an image of a webpage, but need it to fully load (including AJAX) first. The delay time should be predetermined instead of being reliant on a specific element. The code below takes a screenshot without waiting: from selenium import webdr ...

Saving the object returned by the useRef hook into the Redux state

I have a question. I am developing a music platform similar to Spotify using Next.js. To manage states, I am utilizing Redux Toolkit. In order to play music, I have integrated the audio element within a component that includes controls to adjust the music ...