Tips for transferring values from your application to the adapter in IBM Worklight

I am looking for a way to transfer parameters from the application to the adapter, where I want users to provide these options.

Currently, I am passing the parameters in the adapter code like so:


    function getFeeds() {
        WL.Logger.debug("inside method");

        var input = {
            method : 'get',
            returnedContentType : 'json',
            path : "ios/clientRegister.php",
            parameters:{
              "employeenumber":"500","employeename":"Harish","employeeemail":"example@email.com","city":"Delhi", 
              "employeeadID":"an6458","businessUnit":"WASE","country":"India","city":"Bengaluru","location":"EC4","bloodGroup":"B+ve", "gender":"Male","tShirt":"xl"    
            }  
        };
        return WL.Server.invokeHttp(input);
    }

Answer №1

If you want to pass parameters using basic JavaScript, here's an example:

HTML

First name: <input type="text" id="firstname"/>
Last name: <input type="text" id="lastname"/>
<input type="button" onclick="submitName()" value="Submit Name"/>

App JS

function submitName() {
    var data = {
            adapter : 'exampleAdapter',
            procedure : "showParameters",
            parameters : [$('#firstname').val(),$('#lastname').val()]
    };
    
    var options = {
            onSuccess : success,
            onFailure : failure
    };
    
    WL.Client.invokeProcedure(data, options);
}


function success() {
    alert ("success");
}

function failure() {
    alert ("failure");
}

Adapter XML

<procedure name="showParameters"/>

Adapter implementation

function showParameters(firstname, lastname) {
    WL.Logger.info  ("The submitted parameters are: '" + firstname + "' and '" + lastname + "'");
}

To view the logged line, follow these steps:

  1. Open the Servers view in Eclipse

  2. Expand the Worklight Development Server entry

  3. Double-click on Server Configuration

  4. Click on Logging

  5. Change the Console log level from AUDIT to INFO (using the dropdown)

    Full-size image: https://i.sstatic.net/9llHc.png

  6. You may need to Project >> Clean...

  7. The output will be visible in the Console view for the Worklight Development Server

    Full-size image: https://i.sstatic.net/x2Hv1.png

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

Vue.js - Displaying validation errors when a user interacts outside of a component

The ExamEditor Vue component I am working on is quite complex, consisting of sub-components like QuestionEditor and ExerciseEditor. These components are all tied to an exam object that contains nested arrays with questions and more. The layout inside the e ...

Best practices for timeout in HTTP long polling

As an avid user of Javascript AJAX and long-polling, I am constantly seeking the best value for server response timeout. Despite scouring numerous documents, a detailed explanation for timeout continues to elude me. Some suggest 20 seconds, while others ...

Struggling to find the right strategy for obtaining real-time data while implementing customized filters

After spending a week scratching my head and experimenting with different approaches, I'm hoping to find some help here... I am working on an application that needs to provide real-time data to the client. I initially considered using Server-Sent-Eve ...

Can I find a better approach to optimize this code?

How can I refactor this code to move the entire DB query logic into a separate file and only call the function in this current file? passport.use( new GoogleStrategy({ clientID: googleId, clientSecret: clientSecret, callbackURL: ...

Center the title vertically APEXCHARTS

I created this chart using Apex charts https://i.sstatic.net/j34Wc.png However, I am facing an issue where the 'Chart' title and caption are not properly aligned. The title should align with the graph horizontally, and the caption vertically. ...

I am currently working with a for loop within an object in JavaScript, but there seems to be a problem with one

Here is a function called validator: import validator from "validator"; import isEmpty from "is-empty"; export default function validate(data) { const errors = {}; for (const property in data) { console.log(property); //< ...

Creating a JSON data structure that is compatible with Flot chart plotting

Is there a way to convert the following JSON data: [ { "year":"1999", "value":"3.0" }, { "year":"2008", "value":"0.9" } ] into this format: { "data": [[1999, 3.0], [2008, 0.9]] } I need to consider ...

Is it possible to utilize the userId instead of the jwt token in this scenario?

Is it a good practice to hash the userId and store it in local storage, then send unhashed user id in authorization header on every route for server-side validation? Will this approach ensure security? ...

Create and export a global function in your webpack configuration file (webpack.config.js) that can be accessed and utilized

Looking to dive into webpack for the first time. I am interested in exporting a global function, akin to how variables are exported using webpack.EnvironmentPlugin, in order to utilize it in typescript. Experimented with the code snippet below just to und ...

Use regular expressions to exclude occurrences of the character 'n' from your text

Looking for a regular expression to validate input, specifically filtering out all special characters except "underscore". All characters within the range [a-zA-Z0-9\underscore] are permitted and can appear multiple times. However, my expression shoul ...

HTML5 text enhanced with a dynamic shadow effect

Struggling with adding a shadow effect to text in my front-end development project. Using HTML5, CSS3, bootstrap, and AngularJS for the design elements, I want to achieve a shadow effect similar to what you would see in Photoshop on a text field. Can anyo ...

The webpage is displaying an error stating that "<function> is not defined."

I recently duplicated a functional web page into a new file on my site. However, after adding a new function and removing some HTML code, the JavaScript function no longer runs when clicking one of the two buttons. Instead, I receive the error message "Beg ...

Exploring the benefits of utilizing useState and localStorage in Next.js with server-side

Encountering an error consistently in the code snippet below: "localstorage is not defined" It seems like this issue arises because next.js attempts to render the page on the server. I made an attempt to place the const [advancedMode, setAdvanced ...

Glitch in transmitting server data to client in MERN stack development

I am currently developing a MERN web application and I've encountered a bug in which the data retrieved from the server is not matching what is expected when making a GET request on the client side. Below is the controller function on the server for ...

You have encountered an error: [ERR_HTTP_HEADERS_SENT]. This means that you cannot set headers after they have already been sent to the client, even if a return

I've encountered a 'Cannot set headers after they are sent to the client' error with the /api/users/profile route and have been attempting to resolve it. I stumbled upon some solutions on stackoverflow suggesting to add a return statement - ...

What could be causing the inconsistency in this animation, with its choppy movements and occasional lengthy delays before actions are

The animation using jQuery seems to be running inconsistently across different browsers. In Firefox, the animation appears choppy, and in both Firefox and Chrome, there is often a noticeable delay of around 1 second before the animation begins (even though ...

Transition smoothly between sections using fullPage.js with clipping path effects

I am looking to create a unique clipping animation utilizing SVG clipping path. The animation should hide the first section while revealing the second section in a smooth transition using fullPage.js. This idea is somewhat similar to the question discusse ...

Angular does not seem to be triggering $watch for changes in arrays

Trying to activate a $watch function after a delay in Angular: Controller Information .controller('MyCtrl', ['$scope', function ($scope) { $scope.chickens = ["Jim", "Joe", "Fred"]; $scope.chickens.push("Steve"); setTimeou ...

encountering trouble with reading pathname in React Router DOM due to an error

App.jsx import { useState } from 'react'; import './App.css'; import NewsContainer from './Components/NewsContainer'; import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; function App() { const [mode, ...

Cleaning up HTML strings in Angular may strip off attribute formatting

I've been experimenting and creating a function to dynamically generate form fields. Initially, the Angular sanitizer was removing <input> tags, so I discovered a way to work around this by bypassing the sanitation process for the HTML code stri ...