The property 'createDocumentFragment' is not defined and cannot be read in JavaScript code

I'm working on loading data from my database using ajax, but I'm facing an issue with the this method not functioning as expected.

Below is a snippet of my source code:

$(".cancel-btn").click(function() {
  var cancelArea = $('.cancel');

  let userID = $('.person-title').data('user-id');

  $.get(`users/${userID}`).done((docs) => {
    $(docs).each((i) => {
      $(cancelArea).append(
        `<div class='cancel-box text-center' data-sessionID="${docs[i]._id}" onclick='cancelSession()'>
            <div class='cancel-trainer'>${docs[i].trainedByName}</div>
            <div class='cancel-date'>${docs[i].date}</div>
            <div class='cancel-hour'>${docs[i].startTime}</div>
          </div>`
      );
    });
  });
});

Additionally, here is the function that I am attempting to execute:

function cancelSession() {
  console.log($(this).data('sessionID'));
}

Thank you in advance for your help!

Answer №1

Consider using this alternative

<div class='cancel-box text-center' data-sessionID="${documents[index]._id}" onclick='cancelClass(this)'>

JavaScript:

function cancelClass(element) {
  console.log($(element).data('sessionid'));
}

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

PHP is capable of showing echo statements from the function, however it does not directly showcase database information

My current challenge involves using AJAX to pass the ID name of a div as a string in a database query. Despite being able to display a basic text echo from my function, I'm unable to retrieve any content related to the database. // head HTML (AJAX) $( ...

Exploring the intricacies of Django and JQuery interdependent dropdowns: mastering the art of Ajax

I recently followed a tutorial on creating interdependent dropdowns using Django, JQuery, and Ajax. Here is the link to the tutorial: In my project, I have an inline-formset where selecting a product type should only display products within that type. Up ...

AngularJS and Bootstrap carousel combined for a dynamic multi-item per slide display

Currently, I am utilizing Bootstrap to showcase a carousel on my website, where multiple items are displayed per slide as demonstrated in this example. The use of static images has yielded satisfactory results, as evidenced by the jsFiddle example found he ...

What does "t=" represent in the socketIO URL?

I am just starting to learn about socketIO, and I have noticed that every time I connect to a node server through socketIO, it creates a URI that looks like https://XXX:8080/socketIO/1/?t=XXXXXXXXXXX Could someone explain what the "?t=XXXXX" part is for ...

"Discover the trick to adding and updating text in a URL using jQuery without needing to refresh the page

I successfully implemented pagination in WordPress using Jquery/Ajax/wp_pagenavi(). It works well as it only refreshes a specific div to load new content instead of reloading the entire page. However, I am looking to enhance this feature by updating a port ...

I'm experiencing some compatibility issues with my script - it seems to be functioning correctly on desktops but not on mobile

Below is a script I've implemented on an html page to toggle the visibility of divs based on user interaction. <script> $(document).ready(function(){ $("#solLink").click(function(){ $(".segSlide").hide(), $(".eduSlide").hide ...

An issue with the image filter function in JavaScript

I am currently working on a simple application that applies image filters to images. Below is the code I have written for this purpose. class ImageUtil { static getCanvas(width, height) { var canvas = document.querySelector("canvas"); canvas.widt ...

Opera's compatibility with jQuery's Append method allows developers to

I recently wrote a jQuery script that interacts with a JSON feed and dynamically creates HTML code which is then added to a designated div on my WordPress site. Surprisingly, the functionality works flawlessly in all browsers except for Opera - where not ...

Tips on preventing repeated data fetching logic in Next.js App Routes

I'm currently developing a project with Next.js 13's latest App Routes feature and I'm trying to figure out how to prevent repeating data fetching logic in my metadata generation function and the actual page component. /[slug]/page.tsx expo ...

Toggle the input box by clicking the button

How do I show or hide the input box (blue square) when I click the search button (red square)? Link Image I attempted to create the transition in CSS and also experimented with JavaScript, but the JavaScript part confused me. Here is what I tried: $(" ...

Looping AJAX calls in Laravel

Encountering a persistent memory_limit loop issue while trying to store form data in the database has left me puzzled. The cause of this problem remains unclear to me, and I have been unable to find a solution despite adjusting the memory_limit in php.ini. ...

Difficulty encountered while setting up jQuery slider

I am struggling to set up a jquery slider (flexslider) It seems like I am overlooking something very fundamental, but for some reason I just can't figure it out. Any assistance would be greatly appreciated. Please check out the link to the test site ...

How to check Internet upload speed in Angular without using a backend server?

I need help uploading a file to a folder within my Angular app's directory while it is running on localhost. I have been unable to find a solution that doesn't involve using backend technologies. For instance, I simply want to upload an image fi ...

Executing multiple API calls concurrently using callback functions in node.js

Waiting for the completion of tasks from two API callback functions is essential in order to utilize data from both functions. I am looking for a way to parallel execute these functions, but have been struggling with implementing async.parallel. If there ...

Combining CodeIgniter and Ajax for Dynamic Web Development

I'm currently attempting to incorporate an ajax plus one button on my website using code igniter. I am relatively new to Ajax and codeigniter, so I could use some guidance. Here is where I'm starting within my controller. Keep in mind that this ...

Vue 2 draggable does not maintain reactivity when the v-model value consists of a parent tag's iterable

Utilizing Vue 2 alongside Vuex, the incoming object gets organized into distinct sub-objects according to the classCategory value. Could it be failing because the v-model value in draggable is a key sourced from the parent tag object? <div class="c ...

Displaying information on a Rails view

I am a beginner in the world of Rails, so I'm not entirely certain if this is the correct approach to take. Within my view, there is an AJAX link that contains several checkboxes structured like so: <% @row_headers.each do |row_header| %> < ...

Angular index.html file can include a conditional script

I am currently working on an Angular project, where the index.html serves as the main entry point for the application, just like in any other Angular project. This file contains important links and configurations. Within the HTML code snippet below, you w ...

Understanding the difference between Parameters in Javascript and Java

Currently, I am facing an issue where I am losing some information while sending an ajax request to a servlet. The specific parameter that I am losing data from is the "comment" parameter. Below are the last 4 lines of my ajax code: var params = "name=" + ...

Can you identify the issue with this particular JSON parsing function's reviver?

I am trying to parse a JSON string with a reviver function to only include specific properties. Here is my code snippet: const whitelist = ['prop1', 'prop2', 'result']; const reviver = (key, value) => { if (whitelist.i ...