When attempting to load the table from JSON, the error message "Cannot read property 'name' of null" occurs in the fooplugins/Footable plugin

I am facing an issue while trying to integrate the "FooTable" plugin with ajax calls. Everything works perfectly fine when I directly input the JSON data or load it from a JSON file using $.get('....json'). However, when attempting to fetch the table content from my server, I consistently encounter the error message "Cannot read property 'name' of null." Details of this error can be found here:

Error message

The provided image also displays the JSON data logged in the Console. Despite numerous attempts to load it in various ways (both backend and frontend), I have been unable to resolve the issue. Some of my attempts are commented out in the accompanying Code.

JavaScript:

$(document).ready(function () {
jQuery(function ($) {
    var ft = FooTable.init('.table', {
        "columns": $.get('/js/mycols.json'),
        //"rows": $.get('/js/myrows.json')
        "rows": $.get('/api/GetEvents', function (e) {
            console.log(JSON.parse(e.value));
            //ft.rows.load(JSON.parse(e.value));
        }, "json")
    });
    //$.ajax({
    //    url: "/api/GetEvents",
    //    dataType: "json",
    //    type: "GET"
    //}).done(function (e) {
    //    console.log(e);
    //    ft.rows.load(e.value);
    //})             
  });
});

ASP.NET Backend:

List<JObject> objList = new List<JObject>();
foreach (var e in events)
{
    JObject jObj = JObject.FromObject(new
    {
        name = e.Name,
        veranstaltungstyp = e.Type,
        startzeit = e.StartTime.ToString("H:mm - dd MMMM yyyy"),
        ende = e.EndTime.ToString("H:mm - dd MMMM yyyy"),
        erstelltvon = e.CreatedBy.FirstName + " " + e.CreatedBy.LastName,
        render = "placeholder"
    });

    objList.Add(jObj);
}
var result = new JsonResult(JsonConvert.SerializeObject(objList));
result.ContentType = "json";
result.StatusCode = 200;
result.SerializerSettings = new JsonSerializerOptions();
return Json(result);

Answer №1

My experience mirrored yours. It seems like FooTable is attempting to load the rows before the table has finished rendering, causing issues with DOM access.

I recommend wrapping your fetch call in an 'on.ready.ft.table' event listener.

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

Press the button located within the canvas element

How can I click on the verify button embedded inside a canvas element using either jQuery or Selenium? Please advise me on how to successfully click inside the canvas. ...

Is it possible to use both the filter $select.search and the limitTo $select.infiniteCurrentLimit on a single ui-select field?

I am facing a challenge with my ui-select field which utilizes infinite-scroll functionality due to having a large number of options. However, it becomes cumbersome to scroll down and find the desired option among so many choices. <ui-select-choices ...

What is the method to prevent the Submit Button from being active in CSS specifically on Firefox?

When I click this CSS in webpages on Chrome (OS: Windows), it works fine. However, Firefox (OS: CentOS7) does not seem to apply this CSS on webpages. How can I resolve this issue? Should I make adjustments in the CSS code below? #submit .btn.btn-primary ...

Changing TypeScript Enum from String to Number in Angular

Does anyone know how to convert a Typescript enum value to a number for display in a dropdown but passing the numeric value on submit? Here is how the enum is currently set up: I am currently able to output the string key of the object when it is emitted ...

Finding the identification of the first element within a nested div using JQuery

Here is the HTML snippet that I am working with: <div id="parent"> <div id="computer"> <div id="items"> <div id="1">hp</div> <div id="2">compaq</div> <div id="3"& ...

How to Stop AJAX Requests Mid-Flight with JQuery's .ajax?

Similar Question: Stopping Ajax Requests in JavaScript with jQuery Below is the straightforward piece of code that I am currently using: $("#friend_search").keyup(function() { if($(this).val().length > 0) { obtainFriendlist($(this).va ...

ng-hide is not functioning to display the form

I'm trying to display a form using ng-if when the "add" button is clicked, but it's not working. I've looked at several examples and tried them all, but none have worked for me. Here is the code I am using: angular.module('myFormApp&ap ...

Obtain the value of a JavaScript form with a dynamically generated field name

I am struggling with a simple javascript code and for some reason, it's not working. var number = 5; var netiteration = "net"+number; // now netiteration is equal to net5 var formvalue = document.forms.myformname.netiteration.value; Why is this co ...

Tips to choose specific words following a backslash in a PowerShell script from a JSON file

I have a JSON file obtained from an Azure CLI command. I am looking to deploy it using a PowerShell script through a tool like Jenkins or Rundeck. My goal is to extract the "name" field from the JSON, specifically the word that comes after the forward sl ...

Encountering a 404 error while attempting to establish a connection between Express and React

My attempt to make a simple API request for bitcoin values is encountering some issues. When I enter in my Chrome browser, I receive a "Cannot Get /" message with a 404 error in the dev tools stating "GET 404 (Not Found)". However, when I visit , I succ ...

How to add additional text after a particular line within a string containing multiple lines using JavaScript

What is the best way to add a new string after line 2 in a multi-line JavaScript string? ...

Explore JSON pivot table - effortlessly retrieve all data points

Is there a way to display all facilities from my JSON data while still being able to access hotel information? Currently, it only works if I output the facilities alone. JSON Data { "id": "1", "hotel_title": "Name of Hotel", "hotel_description": "1 ...

An error occurs when attempting to assign a value to a MUI file TextField

Struggling with setting the value of a MUI Textfield that has type="file" props, resulting in the following exception being thrown: Uncaught DOMException: An attempt was made to use an object that is not, or is no longer, usable Interest ...

What is the proper way to attach the form tag action value in an EJS template?

Does anyone know about this? I am currently testing some JavaScript code: function mem_join_next() { if (document.mem_join.email.value == "") { alert("please input your email ID"); document.mem_join.email.focus(); return; } documen ...

Experiencing the 'Page prerendering error' message within Next.js

I encountered a prerender error during the deployment phase that I'm struggling to comprehend: Error occurred prerendering page "/about". Read more: https://nextjs.org/docs/messages/prerender-error ⨯ useSearchParams() should be wrapped in ...

Having trouble passing form data to the action method in MVC while using jQuery ajax?

Within my application, I am displaying a report that users can filter. Users input filter data and then click the 'Go' button. When the 'Go' button is clicked, I use jQuery to send the entire form to the controller action. My goal is to ...

Guide on how to load just the content section upon clicking the submit button

Here is an example of my code: <html> <head> <title>Test Loading</title> </head> <body> <div id="header"> This is header </div> <div id="navigation" ...

Using JQuery to monitor the loading of a newly selected image src attribute

As a newcomer to JavaScript and JQuery, I am facing a challenge that I couldn't find a solution for in other discussions: I have a function that retrieves the path to an image (/API/currentImage) using a GET request and needs to update the src attrib ...

Unable to transform JSON array into a string

I am encountering an issue where the server is not responding with the expected data. Instead, I am receiving a token error '<', despite trying various solutions. $(document).ready(function() { $.ajax({ url:"url", dataTyp ...

Struggling to incorporate a logic in ajax using Cakephp2

I have a website built on CakePHP2 and I am looking to incorporate an Ajax function that will redirect to another URL if a specific PHP condition is met. Otherwise, it should display an error dialog. The tutorials I found on Google are quite complex for me ...