Is there a way to send numerous results using these ajax functions through a POST request?

I currently have a function that sends one output, which is 'OPTIONS', as JSON using AJAX. Now I am looking to modify this function in order to POST multiple outputs, let's say two values. How can I adjust this function to handle two values for POST request? Here's the AJAX function I'm using.

function ADDLISITEM(form)
    { 
    var options = form.txtInput.value;
    options = JSON.stringify(options);
    var url = "send_mysql.php";
    var request = null;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    request=new XMLHttpRequest();
     }
    else
    {// code for IE6, IE5
    request=new ActiveXObject("Microsoft.XMLHTTP");
    }
    request.open("POST", url, true);
    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    request.setRequestHeader("Connection", "close");
    request.onreadystatechange = function(){
        if (request.readyState == 4) {
            if (request.status == 200) {
                //alert('POST');
        } else {
            alert(request.status); // fails here
        }
        }
    }
    request.send("options=" + encodeURIComponent(options).replace(/%20/g, '+'));
    }
    </script>

Answer №1

To enhance the request.send function, simply add a new parameter in the following manner:

var additionalData = JSON.stringify({item : "content", included : "here"});
request.send("selection=" + encodeURIComponent(options).replace(/%20/g, '+') + "&additionalData=" + encodeURIComponent(additionalData).replace(/%20/g, '+'));

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

Issue with Gijgo grid not updating properly during change event

I'm currently working on an MVC 5 application and I've hit a roadblock with a particular view. This view contains a dropdown menu and a grid (Gijgo-grid). The grid's content is supposed to change based on the selected value from the dropdown ...

What is the process for including additional information in a JSON file?

I've been searching for a while now and couldn't find the right solution, so I'm posting my issue here. I am trying to add some data (an object) to a .json file, but each time I add more data, it ends up getting messed up. Here's the co ...

Issue with Ajax reload functions malfunctioning

Embarking on a new journey, I am diving headfirst into the world of web development. As an artist and writer, I have recently delved into the realm of creating a project that integrates a cms, project manager, and database front-end using php, mysql, and j ...

`Count the number of rows needed to accommodate text line breaks within a div element`

Is there a method to determine the number of lines that text breaks into using the CSS property word-break: break-all? For example, if I have a div like this: <div>Sample text to check how many lines the text is broken into</div> And the corr ...

How to retrieve the name of a node using partial text in JavaScript

I am looking for a way to separate values into key-value pairs before and after a specified delimiter (:) in JavaScript. For example: Product Name: Product 15 Product code: 1234 If I search for "product," I want to retrieve the product name and product c ...

How can I pass functions from the Parent Context Provider to the Child Context Provider and define them in React?

Recently delving into the world of React, I've encountered a challenge with using the Context API alongside React Functional Components Specifically, I'm faced with a situation where I need to differentiate authentication providers based on th ...

Issue with Cascading Dropdowns in jQuery

I am currently experiencing issues with a piece of code on my website (also accessible via this link). The code consists of 2 select fields that should display different data based on the selection made. However, I have identified 2 bugs within the code. ...

Scaling Images using HTML and CSS

Hey there, I'm currently learning web development and running into a bit of trouble with creating responsive images. Can anyone give me some guidance on what changes I should make in the code below? Here's the HTML code: <div class="caro ...

Tips for safeguarding against Cross-Site Scripting when using the JQuery .append() function

I'm facing a challenge with my ajax call that involves using multiple .append() commands to populate a dropdown list. The security code test application flagged all instances of the .append() command as potential XSS vulnerabilities. Here's the s ...

What is the best way to set up the login page and logged-in homepage using Node, Express, and Passport with the "/" route?

I am currently in the process of developing an application using Node.js, Express.js, and Passport.js. My goal is to create a seamless user experience on the homepage where if you are not logged in, you will see a login form (with potential for additional ...

Verify record removal without a PHP click

My website features a navigation menu that streamlines the browsing experience: <form action="../"> <select onchange="window.open(this.options[this.selectedIndex].value,'_top')"> <option value="" selected="selected">Navigate< ...

"JS Kyle: Utilizing JWT for Signing and Encrypting Data

I am currently using jose for signing and encrypting JWTs, but I am facing an issue when trying to sign and then encrypt the entire JWT. When it comes to signing my JWT, I utilize the following function: const secretKey = process.env.JWT_SECRET; const key ...

Executing Grunt: Setting up a dual Connect and Express server to operate on one port

I'm still fairly new to Grunt and I've been wondering if it's possible to run both servers on the same port simultaneously. I seem to be encountering some issues with this setup, most likely stemming from the Grunt file. I am utilizing grun ...

Retrieve an array of object values using Angular and TypeScript

I'm attempting to extract the values of objects in an array using a nested for loop. I am receiving JSON data as shown below and have written the following TypeScript code to achieve this. However, I am unable to successfully bind the values to the te ...

Retrieve all HTML dependencies, such as JavaScript and CSS files, using the same method as a web browser

I am currently working on a Single Page Application (SPA). My main objective is to evaluate the performance of the application using . Given that the application is an SPA, I want to simulate a scenario where all static content is loaded when a user firs ...

Is it possible to alter objects through the use of jQuery.map?

I'm working with a key-value pair that looks like this: var classes = { red: 'Red', green: 'Green' }; Is there a way to add a specific value before each key in the pair? Can jQuery.map help with this task? The desired end result ...

A bot responsible for assigning roles never fails to remove a role when necessary

My goal was to develop a bot that automatically assigns users a role based on the language they speak in a bilingual server. However, when I tried to assign myself the Czech role, it added the role but failed to remove the rest: const Discord = require(&a ...

Creating a Distinct Interior Array Separate from the Exterior

I'm currently working on a project that involves creating a 2D array. I want the interior elements of this array to be black while the exterior elements should be white. However, my 2D array doesn't seem to be forming correctly - it looks more li ...

"The text() or json() methods in Javascript's fetch function never seem to resolve, leaving the operation in a perpetual

In my new nextjs 13 project, I'm attempting to perform a fetch operation (unsure if it's related to JavaScript or nextjs) and using console.logs to monitor the code execution. let url = `${BASE}/${module}/${path}`; url += "?" + ne ...

Overlap of sub menus

Seeking assistance from a CSS expert for a challenge I am facing. I am currently working on a toggle menu for mobile view, and encountering issues with the submenu. Any list item placed below another one with children is not visible. Removing the parent l ...