When I attempted to POST a js::array in JSON, the response returned "undefined:undefined"

I have a javascript array on the frontend that I need to send to my Tomcat server.

Currently, I am using the following code but encountering issues:

        console.log("preview list. postUsers()");
        console.log(Ext.getCmp("preview-container").getUsers());
        $.ajax({
            url: "url",
            type: "POST",
            data: Ext.getCmp("preview-container").getUsers(),
            dataType: "json",
            success: function(rst){
                switch (rst){
                case true:
                    alert("success");
                    break;
                case false:
                    alert("failed");
                    break;
                }
            },
        });

The object looks like this:

preview list. postUsers() 
["18241", "44598", "46558"]

However, the result of the POST request is:

   undefined=undefined&undefined=undefined&undefined=undefined&...

This result is being interpreted as:

undefined: undefined ...

Is there something crucial that I may be missing?

Answer №1

It appears that the post request parameter name is missing from your code snippet

console.log("preview list: postUsers()");
console.log(Ext.getCmp("preview-container").getUsers());
$.ajax({
    url: "url",
    type: "POST",
    //send the users using parameter `users`
    data: { users: Ext.getCmp("preview-container").getUsers()},
    dataType: "json",
    success: function(rst){
        switch (rst){
            case true:
                alert("Success");
                break;
            case false:
                alert("Failed");
                break;
        }
    },
});

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

Prevent the button from being enabled until the file input is updated

I want to create a form with an input file for uploading photos, but I need the submit button to be disabled until the input file has a value. Additionally, there are other validations that will also disable the button. Here is the structure of my HTML fi ...

Guide on transferring data from an API using mapped React hooks

I am working with react hooks and attempting to pass a value to the delete function and execute the put function <Fab aria-label="delete" className={classes.fab} value={vacation.id} ...

What is the most efficient approach to managing a large single JSON response in a RESTful context?

Instead of paginating the response when dealing with many documents, I face a unique challenge where each document in the response can be very large. How should I handle this situation? To illustrate, let's look at the following sample JSON: { "exc ...

Searching through text in Node JS using Mongoose for Full-Text queries

I am facing an issue while attempting to perform a full-text search on an array of strings using Mongoose. The error message I receive is as follows: { [MongoError: text index required for $text query] name: 'MongoError', message: 'text ...

Transform a "flat" array into one that mimics a hierarchical directory structure

I am working with a collection of "directory objects" that have the following structure: $directoryObjects = [ [ 'type' => 'folder', 'name' => 'animals', 'path' => &apo ...

What is the best way to add a value to the value attribute of a div using JavaScript?

Is there a way to insert a value into the value attribute of a div using Internet Explorer 9? I have attempted various JavaScript functions, but so far I can only modify the content inside the div and not the value attribute itself. <div id="mydiv" val ...

The javascript function in my file isn't being triggered by jquery

In my ASP.NET MVC project, I am facing an issue with a jQuery function in a JavaScript file located under the Scripts folder. This function is supposed to fill a textbox with the selected value upon clicking a dropdown, but for some reason it is not workin ...

Error: The function 'toEqual' is not recognized by the 'expect' method causing

I've been following along Dan Abramov's Redux tutorial which can be found at () Lesson 9 covers testing and the usage of expect and .toEqual() This is the code I'm working on: var expect = require('chai').expect; var freeze = re ...

Vue - component props not properly updating when object changes are made

Within the main structure, I have both obj and newObj objects. I am monitoring any changes that occur within the obj object using deep: true, and then updating newObj accordingly. Although in my vue debugger, it appears that newObj has been updated as exp ...

execute bower install for the specified bower.json file

Let's say my current working directory is c:\foo\ while the script is running. I want to execute bower from there for the c:\foo\bar\bower.json file. This can be done in npm by using npm install --prefix c:\foo\bar. ...

Minimize the number of clicks needed to navigate using the HTML/JavaScript navigation

On my website, I have a navigation bar that changes the contents of a div when a user clicks on an item. However, if the user clicks multiple times in quick succession, the content changes too many times. I want to ensure that the content only changes once ...

The function screen.getByText is not available in this context

My experience with jest and react-testing-library has been smooth for the most part, but I encountered some challenges when transitioning to the screen > getByText/etc testing method. Test describe('test the dashboard when loaded', () => { ...

Learn how to import a stylus file globally in Vite build tool

Recently, I decided to use vite for building a new vue application. However, I encountered some difficulties when trying to globally import a stylus file in my vite.config.js. I followed the code examples provided in the vite documentation: export default ...

Is there a way to retrieve posts by year and month using nextjs and contentful?

Currently, I am in the process of setting up a blog using Next.js and Contentful CMS. The structure of my folders is set as follows: pages/blog/[year]/[month]/[slug].js Each year and month folder contains its own index.js file. Currently, my focus is on ...

Troubleshooting graph explorer issues related to batch processing has been

By utilizing Graph Explorer, I am able to retrieve the photo of a group with the request $value. The response preview accurately displays the photo. However, when attempting to access the photo of the same group using batch $batch, { "requests": [ ...

Tips for utilizing SlowCheetah to modify array elements within a Json configuration file

Today is my first time working with SlowCheetah to transform a JSON configuration file. I am facing an issue where I cannot figure out how to transform an array of settings. For instance, if my original config file contains the following setting: { "Set ...

Navigation menu with submenus containing buttons

I attempted to incorporate a dropdown into my existing navigation bar, but unfortunately, the dropdown content disappeared after adding the necessary code. I am now at a loss on how to troubleshoot this issue and make the dropdown function properly. Despit ...

How can we integrate information from a local JSON file onto our website?

My role is with a small publishing company that has an internal website featuring a static HTML table showcasing our published products. We are looking to dynamically list and sort our products (with about 1-2 items published daily) based on data from an ...

Is it possible to make the entire div clickable for WordPress posts, instead of just the title?

I am currently facing an issue where only the h1 element is linked to the post, but I want the entire post-info div to be clickable. Despite my efforts, I haven't been able to make the whole div clickable, only the h1 element remains so. Below is the ...

encountering issue alerts when using the MUI TextField module alongside the select function

Encountering an error in the MUI console: children must be provided when using the TextField component with select. <TextField select id="outlined-basic" label="User Name" name="user" size="small" {...teamForm.getFieldProps("user")} erro ...