How can I send an array in a XHR.get request with Luci on openwrt?

I am attempting to send an array from JavaScript to a XHR GET request in Luci OpenWrt.

Let's say, we have an array named myarray[] with some contents like this: `myarray[] = {"1","2","3"}` 

I want to pass this array as arguments to the XHR.get requests. How can I achieve this?

Here is a sample code snippet:

XHR.get('<%=REQUEST_URI%>', {status: 2,value: myarray},
    function(x, info) {
        if (!info) {
            location.href=location.href;
        }
        else {
            console.log("success");
        }
    }
);

In Lua code, I am then receiving this form data:

If luci.http.formvalue("status") == "2" then
    local DetailValue[] = luci.http.formvalue("value")
    local fileContent = {
        content = "sample1",
        find = "sample2"
    }
    luci.http.prepare_content("application/json")
    luci.http.write_json(fileContent)
    return
end

However, I am encountering errors. Is this the correct way to send an array via XHR.get? Any suggestions would be appreciated.

Answer №1

Here is an illustration showcasing a single value example

XHR.get('<%=url('admin/services/sample')%>',  { demo : 'testing' }, function(x) {
        <execute desired actions>
});

function interpret_gateway()
    local demo = luci.http.formvalue("demo")
end

When I tried to include two query parameters with identical keys, I encountered the following scenario

XHR.get('<%=url('admin/services/sample')%>',  { item1 : 'test', item2 : 'test1' }, function(x) {
        <execute desired actions>
});

function interpret_gateway()
    local demo = luci.http.formvalue("demo")

This time around, the "item2" was set as test1

Therefore, in your situation, it appears that unique parameter keys are necessary.

XHR.get('<%=url('admin/services/sample')%gt;',  { first : '1', second : '2', third : '3' }, function(x) {
        <execute desired actions>
});

function interpret_gateway()
    local first = luci.http.formvalue("first")
    local second = luci.http.formvalue("second")
    local third = luci.http.formvalue("third")

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

Dynamically scrolling using SuperScrollorama and Greensocks

I'm currently facing a JavaScript animated scroll challenge that has me scratching my head. My approach involves using the SuperScrollorama jQuery plugin, which relies on the Greensock JS tweening library. The main effect I'm aiming for is to " ...

Having trouble installing gulp locally due to an error with ` ode_modulesansi-regex`

While attempting to set up Gulp on my Windows 10 system, I encountered an error during the local installation process. $ node -v v9.10.1 $ npm -v 5.6.0 I successfully installed Gulp globally: $ npm install --global gulp-cli $ gulp -v CLI version 2.0.1 ...

"Manipulating time formatting within an array with the help of moment.js, AngularJS, and lodash

I am working with JSON data that includes timings based on dates. obj = { "2017-12-08": [ "2017-12-08T13:00:00+0530", "2017-12-08T15:00:00+0530", "2017-12-08T15:30:00+0530", "2017-12-08T16:00:00+0530" ], "2017-12-09": [ "2017-12-09T09: ...

Moving from _document.tsx to layout.tsx and managing additional server attributes

In the past, I utilized _document.tsx to manage certain script logic that needed to be executed very early. For instance, I used it to implement dark mode code to prevent flickering that may occur with useEffect. Here is an example of my _document.tsx: im ...

Is it possible to update the useContext value within a child component so that all other child components can access the updated value?

Is there a way to set a default value (like null) in a parent context and then change that value in a child component so other children can access the updated value? For example, imagine we have an App.jsx file where a userContext is created and passed do ...

What steps should I take to address the issue of sanitizing a potentially harmful URL value that contains a

I've encountered a URL sanitization error in Angular and despite researching various solutions, I have been unable to implement any of them successfully in my specific case. Hence, I am reaching out for assistance. Below is the function causing the i ...

Unable to save a string value from a function to MongoDB is unsuccessful

I've hit a roadblock. Working tirelessly to solve a persistent bug, but it feels like I'm getting nowhere. What am I missing? My goal is clear - once the user submits a form with the enctype of "multipart/form-data", I want to extract t ...

Managing SQLite errors when using JavaScript and ExpressJS

I have developed a Backend route to retrieve games based on specific letters provided. Below are the two routes that I implemented: router.get("/public/gamelist/:letter", (req, res, next) => { var sql = "SELECT title FROM Games WHERE ti ...

Having trouble aligning a div in the middle of a slick-slider item using flex styling

I've created a slick slider component in Vue, and I'm facing an issue with centering a circular div inside each of the slider items. Despite trying to align and justify center along with adding margin:auto for horizontal centering, I can't s ...

Is there a way to emphasize text within a string of object array items?

I am currently utilizing the data provided below to pass as props in React. The functionality is working smoothly, but I have a specific requirement to only emphasize the words "target audience" within the text property. Is there a feasible way to achieve ...

What is the best way to turn a list into a dictionary with the key representing the index and the value representing the

Consider the following list: a = [0.41 1.87 1.10 7.05] I aim to create a dictionary structured like this: d = {0: 0.41, 1: 1.87, 2: 1.10, 3: 7.05} Although there are multiple solutions available on SO for converting a list to a dictionary, I have n ...

Is it possible to send an ajax request within another ajax request?

I'm facing an issue with a php file that is sending an ajax request to another file located on a different domain name. The receiving parser then processes the information and sends it via ajax to yet another php file where the final action is carried ...

Implementing a dynamic table filter for every column using AngularJS

I have been working on a project to create a custom directive that generates a table with dynamic data and allows for sorting of columns. While the sorting function works as intended, I now want to implement filtering on all columns without specifying a sp ...

Retrieve the 'message' data from the Meta-Data section of the response after sending an Ajax post request with React

After making an Ajax post request, I received the following response snippet: Data: Meta-Data: Topic : "Sign-Up" Message : "Already in the System!" Response Code : "650" . . . I'm trying to figure out how to extract and display the mes ...

Pictures are not showing up in the gallery after they have been saved

if (action.equals("saveToGallery")) { JSONObject obj = args.getJSONObject(0); String imageSource = obj.has("imageSrc") ? obj.getString("imageSrc") : null; String imageName = obj.has(" ...

Using intricate document text as the input parameter in Vue: A guide

I am currently working with this Vue code snippet: <script> var starting_point = '{{ form.content.data }}'; vm = new Vue({ el: '#editor', data: { input: starting_point }, computed: { compiledMarkdown: function () ...

Troubleshooting PHP Errors Following an Ajax Response in CodeIgniter Framework

I am currently developing a unique ecommerce website. To experience the issue I'm facing firsthand, you can visit the link below. take a look at my custom ecommerce site » (username: alex, password: superman) The problem I'm encountering is t ...

Juggling Asynchronous GET Requests in JavaScript?

Despite my efforts to find a solution, I'm struggling to come up with the right words or approach... here's the situation: In my ASP.NET MVC application, users scan inventory or package barcodes. Each scan triggers an async request, and a popup ...

Arrange the items that are missing from Array B to be located at the bottom of Array A, organized in a file tree structure

I have two arrays containing different types of objects. Each object in the arrays has a title assigned to it. My goal is to compare these two arrays based on their titles and move any files that are not included in the bottom part of the fileStructure arr ...

In Javascript, assign default values to an array and update them with new values upon the click of a

My goal is to create a quiz that populates an array. Initially, the quiz is empty but I aim to assign it a default value. This serves as my question navigation: /** * * @param {int} question * @returns {QuizPart} ...