Extracting Post data with Ajax and VbScript in test.asp

I'm currently working on implementing AJAX for my website. Due to the large size of data, I need to use the POST method to send data to the database. However, I am facing an issue with fetching the POST variables in the test.asp file.

Below is the script I have been using:


function SaveData(content ) 
{
    var xmlhttp;
    if (window.XMLHttpRequest)
    {
        xmlhttp = new XMLHttpRequest();
    }
    else
    {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
            var msg = xmlhttp.responseText;
            alert(msg);
        }
    }

    var para = encodeURIComponent("content="+content)
    xmlhttp.open("POST","test.asp",true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
    xmlhttp.send(para);

}

And here is the code in test.asp:


t = Request.form("content")
Response.write(t)

If anyone can help me solve the issue of fetching the POST method variable in test.asp, it would be greatly appreciated. Additionally, any assistance or example code using jQuery AJAX with the POST method in ASP classic would also be very helpful.

Answer №1

In order to make the required adjustment, you must alter the following code:

var para = encodeURIComponent("content="+content)

to this revised version:

var para = "content=" + encodeURIComponent(content);

The initial code would submit data in this format to the server:

content%3Dtest%20data%20123

However, with the updated line of code, the submission will look like this, which is correct:

content=test%20data%20123

Have you thought about utilizing a JavaScript library like jQuery? Using a library would help simplify this process:

$.post("test.asp", { 'content': content }, function(data) {
    alert("Returned data: " + data);
});

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

Is there a way to export the HTML table content to an Excel sheet that is compatible with browsers such as Internet Explorer, Mozilla Firefox, and others?

Welcome to my HTML Page! <html> <head> <title>Table </title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script> <script> </script> </head> <body> <table ...

My JavaScript code seems to be malfunctioning as the content from my two-question form is not appearing within the central div. Is there anyone available who can help troubleshoot and correct my JavaScript

Can someone help correct my JavaScript code and explain the necessary steps taken to do so? I'm trying to figure out what mistake caused my quiz questions and options to not display correctly within the central div. Giving some background on my code: ...

Getting a null value for active user after completing the sign-in process

I am using local storage to store username and password. However, I am encountering an issue where the active user is returning null after a certain line of code, and I am unsure why. console.log("I am the Active user: " + activeUser); const me ...

Unexpected outcome when utilizing localeCompare options in Node.js

Comparing Output from CLI and Chrome Console: > var a = 'foo12'; undefined > var b = 'foo3'; undefined > var s = [a , b]; undefined > s.sort(function(a, b) { ... return a.localeCompare(b, 'en', { numeric: true }); ...

The screen should smoothly slide upwards when the keyboard pops up, ensuring the footer remains und

Hello! I am currently in the process of developing a mobile app using HTML, CSS, Bootstrap, and JavaScript. I have encountered a slight issue where the keyboard does not automatically pop up and move the screen up when the user taps on the textbox in the f ...

JestJS: Async testing isn't halted

I am facing two issues with my jest test: Is there a way to define the Content collection only once instead of repeating it inside the test? I encountered this error: Jest did not exit one second after the test run has completed. This usually indicates ...

What is the best way to generate a 3x3x3 blank matrix in JavaScript?

I am attempting to construct a 3*3*3 matrix where each element will hold a cube. Currently, all the cubes are arranged in a 1D matrix called all_cube. However, I need to organize them in a 3D matrix named cube[][][]. Below is the code for a more detailed ...

Automatically forward to m.example.com on mobile devices using nodejs

Is there a way to create a subdomain in Node.js, such as m.example.com, and have it redirect to m.example.com on mobile devices? I've searched for answers but haven't found a satisfactory solution. One suggestion is to use nginx in front of Node, ...

Is there a way to clear the input value in the otp field?

Here is the codepen link I mentioned earlier: https://codepen.io/santoshch/pen/LYxOoWO <button @click="resetNow(id)"></button> resetNow(id){ this.$refs[`input-${id}`].input.value = ""; //In some cases, you may need to u ...

Navigating cross-domain errors and managing Windows Communication Foundation (WCF)

I encountered an issue while attempting to make a cross-domain jQuery AJAX call to my WCF webservice. Initially, I used the CORS approach but found that the error block was not triggering as expected. However, when I switched to the jsonp approach, it work ...

Trigger audio files in the array at a 0.5-second interval

Currently, I am in the process of developing a Simon game, but I have encountered a roadblock that I am struggling to overcome. My main challenge lies in handling the array with the currentSequence that holds random sounds from another array. I have establ ...

Encountering Webpack issues following the transition to Next 13

Since updating Next to version 13, we've encountered issues with our application not building properly. It appears that webpack is having trouble with imports, exports, and potentially typescript. ../../libs/queries/src/lib/groq/searchFaq.ts Module pa ...

Is it possible that MapBoxGL installation with Expo doesn't function properly for web?

I have been working on building an app featuring a map using the MapBoxGL library in Expo. I followed the installation instructions provided by the library, which can be found here. After completing the installation, I proceeded to write the code below to ...

Authentication for single-page applications using the Angular framework and Play Framework in the Java programming language

I'm seeking guidance on how to design an authentication mechanism using Angular front-end and Play Framework (Java) back-end. Here's the basic concept: Angular sends a REST authentication call to the Play Framework. Play generates a token and s ...

Assigning the image source to match the image source from a different website using the image ID

Would it be possible to retrieve the URL of an image from a different webpage using its img ID, and then implement it as the image source on your own website? This way, if the image is updated on the original site, it will automatically update on yours as ...

What is the process for updating information in Vue.js?

I need assistance with displaying the updated data in a modal. When I trigger the testing(data) function through a click event, the data appears correctly within the function. However, the template does not update and still shows the previous data. How can ...

The JavaScript-generated form element will not be included in the data submitted through the POST method

While it may appear that this question has been asked before, my specific inquiry seems to be unique as I have not found a similar answer in other threads. Therefore, I am initiating a new discussion. My issue revolves around a form which contains a link ...

There are multiple sets of radio buttons within nested ng-repeats, but only the final group displays the selected value

I am having an issue with updating a form that contains multiple radio buttons based on data retrieved from an API. The challenge is that only the last set of radio buttons displays the value correctly. Below is the code snippet I am using (angular bracket ...

Double curly brace Angular expressions being repeatedly evaluated during mouse click events

Within our Angular application, the code structure is as follows: <div>{{ aGetProperty }}</div> <div>{{ aMethod() }}</div> Upon clicking anywhere on the page, these expressions are being evaluated repeatedly. For example, if there ...

Would parallax stars be overwhelming for a webpage?

I'm a newcomer to the world of web development and I have an idea to make stars move across my website. However, I'm concerned about whether this might be too much for a simple website to handle. Is there a way to optimize the code? const canvas ...