Attain worldwide reach

I'm currently facing a Scope issue that has been quite challenging to resolve. The saying goes, "a picture is worth a thousand words," and in this case, it couldn't be more true. Whenever the OK or REJ buttons trigger the reject() function, passing the user_id as id parameter, I encounter an error in Firefox's JS console: "ReferenceError: BUUS123US163 is not defined." Interestingly, while the error does mention the specific id needed, my attempts with shallow and deep copies into a Global array called theUsers have proved ineffective. Could someone please shed light on what seems to be a persistent Scope problem?

Update: JSON.parse error In the .catch clause of the reject() function

// obtaining function: JSON.parse error

    function reject(id) {

      console.log("hey: rejection is executed... ");
      // User Data
      const data2 = {
        user_id: '',
        utility: 'delete'
      }

      data2.user_id = id;

      // // POST  :  provide user
      http.post('http://localhost:9999/Password/empapproval', data2)
        .then(data => console.log(data))
        .catch(err => console.log(err));

    }

// http.post invokes the following:

    post(url, data) {

        console.log("easyHttp is executing ...");


        return new Promise((resolve, reject) => {

            console.log("easyHttp Promise is executing ...");

            fetch(url, {
                method: 'POST',
                headers: {
                    'Content-type': 'application/json'
                },
                body: JSON.stringify(data)
            })
                .then(res => res.json())
                .then(data => resolve(data))
                .catch(err => reject(err));
        });

    }


https://i.sstatic.net/uPkS7.png

Answer №1

It seems that when passing the id as a simple argument to the reject and ok functions, it needs to be quoted for evaluation in the correct way. For example, reject ("some-id") instead of reject(some-id). Therefore, the code on line 224 should be modified to:

<td><button onclick="reject('${d.user_id}')" class="" ...

as opposed to

<td><button onclick="reject(${d.user_id})" class="" ...

In addition, using this.id may not be entirely logical, as the this context only gives you access to your element when using jQuery event listeners, not HTML "onclick" attribute listeners. It seems like it should just be id, which is the argument passed to the function. Alternatively, after inserting the HTML, you can do

$(el).on('click', function() { var val = this.dataset.value; /*...*/ });

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

Creating a function to update data in a Node.js/MongoDB environment

Hey there! I'm new to working with nodejs and mongodb, and I'm trying to create a function that updates the win, lose, and draw record in my UserSchema. Here's my Schema: UserSchema = new mongoose.Schema({ username:'string', ...

When attempting to change the text in the textarea by selecting a different option from the dropdown list, the text is not updating

I am facing an issue with three multi-select dropdown lists. When a user selects options from these lists and then presses the submit button, the selected text should display in a textarea. However, if the user manually changes some text in the textarea ...

Interested in transforming and showcasing dates within a MySQL database?

Here's a form with 10 JQuery UI date pickers set up: $(function() { $("#datepicker").datepicker({ minDate: 'today', maxDate: "+90D", showOn: "button", buttonImage: "images/calendar-new2.jpg", buttonImageOnly: true, dateFormat: "D, dd M, yy" ...

Error Encountered: Invalid request while attempting to authenticate with Docusign Python SDK

Trying to utilize the Docusign Rest API by following the sample code on the Python SDK available on Github at this link: https://github.com/docusign/docusign-python-client. After replacing the required values with the obtained keys and URLs from Docusign, ...

Access account using lightbox effect for the login form

In my simple CSS code, I have used a litebox view. I removed unnecessary CSS properties to keep it clean: <style> .black_overlay{ display: block; } .white_content { display: block; } < ...

How to Handle Empty Input Data in JQuery Serialization

Having an issue with a form that triggers a modal window containing another form when a button is clicked. The second form includes an input field and send/cancel buttons. The goal is to serialize the data from the modal form and send it to a server using ...

The integration between React hook form and reactstrap input components is not functioning properly

Having an issue with react-hook-form and reactstrap. The component List.jsx is causing trouble: import { useContext, useEffect } from "react"; import { ListContext, ADD_LIST } from '../providers/ShoppingListProvider'; import { Link } from "react- ...

Prevent parent from scrolling when hovering over a div in HTML5

Unfortunately, the scrolling attribute is not supported in HTML5. I'm facing an issue where I have an svg inside an iframe within a div, and I need to enable scroll functionality within the div while preventing the page from scrolling at the same time ...

What is preventing me from sending a JSON object to a WCF web service?

I completed an intricate app using the old "ASMX" web service implementation and am now transitioning to WCF. I am encountering a frustrating issue - my AJAX calls are failing no matter how I structure the call. It worked smoothly with ASMX but not with WC ...

Interacting with the DOM of an iFrame from a separate window using Javascript

My main webpage is hosted on "DomainA" and it contains an iFrame sourced from "DomainB". Within this iFrame, there is a click event that opens a new window, also sourced from "DomainB". I am attempting to update an input field within the iFrame from the n ...

What is the correct way to handle JSON responses with passport.js?

In my Express 4 API, I am using Passport.js for authentication. While most things are working fine, I have encountered difficulty in sending proper JSON responses such as error messages or objects with Passport. An example is the LocalStrategy used for log ...

Identify Pressed Shift Key Direction - Leveraging JQuery

I am currently working on a web application that requires users to enter capital letters. However, I want to restrict them from using the right shift key for certain keys like a, s, d, f and the left shift key for h, j, k, l in order to detect whether they ...

Creating dynamic form groups that allow for the addition and removal of forms while assigning unique identifiers and names to each input field

I am currently immersed in the development of a sophisticated CMS system. My main objective is to dynamically add and remove form inputs using JavaScript upon clicking a button, with the ultimate goal of submitting the data into a database via PHP script. ...

An error occurred while trying to initialize the ui.bootstrap.demo module in AngularJS

Currently, I am in the process of learning angularjs and have encountered a roadblock. An error keeps popping up: ncaught Error: [$injector:modulerr] Failed to instantiate module ui.bootstrap.demo due to: Error: [$injector:nomod] Module 'ui.bootstr ...

Error message "Python numpy 'exceeds the number of indices for the array'" occurs when there

I am trying to store series of data from a data frame into a two-dimensional array. However, when I run the code below, I encounter an error stating 'too many indices for array'. Additionally, even after manually adjusting the shape of the array ...

There is an issue with GraphView's GraphViewSeries being null

Why is my GraphViewSeries always null even though I have values in my GraphViewData? Take a look at my code snippet below: GraphViewData[] graphViewData = new GraphViewData[1000]; for (int i = 0; i < listprice.size(); i++) { Log.e( ...

What could be the reason for the failure of my class isInstance() check

Do you see any issues with the object being an instance of ChatRoom? Let me know your thoughts. Class: export class ChatRoom { public id?: number; public name_of_chat_room: string; public chat_creator_user_id: number; public chat_room_is_active: 0 ...

Why is My TensorFlow.js Model for Predicting 2 Table Multiples Not Producing Accurate Results?

I have created a tensorflow.js model that predicts outputs in multiples of two. For example, if the input is 16, the prediction should be 32. However, even after providing the input data and labels accordingly, the output printed is [[1],] after prediction ...

Use jQuery to activate the radio button inside a div whenever it is triggered by a change

How can I check which radio button list is clicked and then send a jQuery ajax call for the clicked item? Currently, I have tables with the IDs plan1, plan2, plan3 generated using PHP. Each table has a radio button list. Using jQuery each, how can I achiev ...

Using React.js to create table cells with varying background colors

For my React application, I am working with a table that utilizes semantic ui. My goal is to modify the bgcolor based on a condition. In most cases, examples demonstrate something like bgcolor={(condition)?'red':'blue'}. However, I requ ...