Utilizing JavaScript variables and AJAX to dynamically populate a form with JSON data. Implementing the .jsonForm() method with a designated

Currently, I am utilizing JsonForm which can be found at https://github.com/joshfire/jsonform/wiki#wiki-getting-started.

My objective is to load a form schema into $('form').Jsonfrom() from an external .txt file.

To achieve this, I decided to load the schema into my .html file using ajax, store it in a javascript variable, and then trigger $('form').Jsonfrom() with a click event.

This is the code snippet I have been working on:

<script>    
#Load in .txt to javascript variable using ajax    
var stringData = $.ajax({
                    url: "schema.txt",
                    async: false
                 }).responseText;

#Check that the file loads correctly. - Have verified this works.
#alert(stringData);

#Upon clicking text within a <p> wrapper, execute jsonForm function.    
$(document).ready(function(){
  $("p").click(function(){
       $('form').jsonForm(stringData)
  });
});    

</script>

The error message reported in Firebug reads as follows:

"TypeError: this.formDesc.schema is undefined"

Here is my stack trace for reference:

I suspect that the issue might lie in loading the .txt file via ajax.

However, when I uncomment: alert(stringData); . . . the schema for the form displays perfectly.

Demonstrated here:

Additionally, there doesn't appear to be any problem with the schema itself since I tried directly inserting it into $('form').Jsonfrom("here") and it functions without issues.

Answer №1

Successfully resolved the issue.

Switched to utilizing a templating language (jinja2) instead of ajax in order to integrate my form schema into the html document. This allowed the json form (a jquery form builder) to function correctly when the full html page loaded.

Foolish mistake!

Hopefully this information is beneficial.

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

Exploring the Power of Modules in NestJS

Having trouble with this error - anyone know why? [Nest] 556 - 2020-06-10 18:52:55 [ExceptionHandler] Nest can't resolve dependencies of the JwtService (?). Check that JWT_MODULE_OPTIONS at index [0] is available in the JwtModule context. Possib ...

Tips for sending props to Material UI components

Hey there! I'm currently working on a progressbar component that utilizes animations to animate the progress. I've styled the component using Material UI classes and integrated it into another component where I pass props to customize the progres ...

Creating a private variable to perform a select_sum query

I have defined private variables in my CodeIgniter code like this: private $table = 'phone'; private $column_order = array(null, 'name', 'price'); private $type = array('type'); private $battery_consumption = array ...

I am having trouble displaying SASS styles in the browser after running webpack with node

In my current project for an online course, I am utilizing sass to style everything. The compilation process completes successfully without any errors, but unfortunately, the browser does not display any of the styles. The styles folder contains five file ...

Utilizing AJAX Requests in jQuery Widget Elements for an Interactive Dashboard

I recently implemented the jQuery Dashboard plugin on my site to showcase information from a MySql table. Each widget contains buttons corresponding to the results, which when clicked trigger an ajax call to fetch and display a styled form in a jQuery dial ...

Is there a way to retrieve a website and make changes to its HTML and CSS?

I am interested in developing a platform where I can retrieve someone's website and present it using my own CSS. Additionally, I want to remove certain HTML tags from the retrieved content. Can you provide any guidance on how I can achieve this? What ...

Learn the technique in Vue to separate a string using commas and store the values in an array

As a Ruby enthusiast, I am delving into the world of Vue. In my project, users can input multiple styleCodes separated by commas. I aim to store these styleCodes in an array for flexible length calculations. See my code snippet below: <template> &l ...

When utilizing custom modules in Node.js, is it more effective to require the module from within a function or at the top of the script?

I have developed a custom script that includes all of my common settings and functions. One specific function within this script takes a timestamp as input and outputs a human-readable date with a customized format using Moment.js. The custom script is st ...

How to display a video with full height and width using CSS or JavaScript

I am trying to incorporate an html5 video (using the video tag) with 100% width and 100% height to play in the background. I have seen an example using an image, but I want to achieve the same effect with a video. Here is the code I have so far: #video { ...

Display a modal window in Bootstrap when the countdown timer reaches zero

I am facing another challenge. I am trying to set up a scenario where a countdown timer triggers a modal window to appear once it reaches 0. I have the codes for both the modal and the countdown timer, but I am struggling to figure out how to make them wo ...

What is the best way to save a large quantity of objects to a server using ajax and php?

Imagine a scenario where I have a page containing 100 objects, each around 700 bytes when converted to json format. When it comes to saving these objects to the php based controller, there are several options available to me. Option 1: For each object ( ...

Hovering over an image and trying to rotate it results in

Check out my rotating image example on hover in React here This effect utilizes scale(), rotate(), and transition properties to create an animated rotation when hovering over the parent element. Additionally, overflow: hidden is applied to the parent elem ...

A white background emerges when I select md-dropdown

Lately, I've been experiencing an issue on my website where a white background pops up whenever I click on a dropdown (md-select) in my form. Initially, it only happened with forms inside a modal, but now it's affecting dropdowns across the entir ...

Styling images and text in CSS within a jQuery UI autocomplete widget

I am currently using an autocomplete widget that displays text along with images. The results I have right now are not meeting my requirements. I want to customize the appearance of my results so that the words 'test' and either 'Federico&a ...

Difficulty in modifying an object's property/value using a variable within a function

VueJS is the framework I am currently working with and I am attempting to utilize v-model to link checkboxes to values stored within an object: jobsChecked: {Baker: false, Cook: false, Miner: false} // etc... Here is the checkbox element setup: <div c ...

Run JavaScript on every website when the page loads

After loading all or specific pages in the browser, I am looking to run JavaScript code (predefined code). Are there any browsers and plugins/components that allow me to achieve this? The manual method involves opening the console (e.g. firebug) and execu ...

What's the best way in Angular 6 to set focus on an element that's being made content editable?

I am currently utilizing the contentEditable attribute in Angular 6 to allow for editing the content of elements within an ngFor loop. Is there a way to focus on a tag element when its contentEditable attribute is set to true? <div class="tag" *ngFor= ...

Guidelines for storing information in a database utilizing jQuery and JSON within an asp.net framework

I've been developing an application that utilizes jQuery and JSON to store data in a database. Here is the script function I have written: <script type="text/javascript"> function test() { $(document).ready(function () { var Email = document.ge ...

Is it possible to trigger a single event listener by either of two events?

I need a search functionality that triggers a method on a bean either through a click event or a blur event, whichever occurs first. This is necessary because I want the search results to display as the user types, but also to work if the user copies and p ...

Tips for transferring data and events between named views within Vue Router

I have a layout structured like this: .------------------------+----------------. | Current Tab Title | Controls | +------------------------+----------------+ | Tab1 Tab2 [Tab3] | +---------------------------------------- ...