Change json data with multiple dimensions into an array using JavaScript

I have been attempting to retrieve each member by converting a multidimensional JSON stored in longtext format within MySQL to an array in JavaScript, but unfortunately, my attempts have not been successful.

Here is the approach I have taken:

Firstly, I extract the data from MySQL and convert it into JSON format using PHP.

if( isset( $_GET ) ){
    $id = $_GET['id'];
    $conn = db_connect();
    $id = mysql_fix_string( $conn, $id );
    
    $result = $conn->query("select _usage from SVM where id='$id'")or die(mysqli_error( $conn ));
     
    $rows = array();
    while( $re = mysqli_fetch_assoc( $result ) ){
       $re['_usage'] = n12br( $re['_usage']);
       $re['_usage'] = html_entity_decode( $re['_usage']);
       $re['_usage'] = stripslashes( $re['_usage'] );
       $rows[] = $re;
    }
    print( json_decode( $rows ));
}   

Now moving onto the JavaScript portion:

$(document).on('click', '.view-subtitle', function(e, ele){
       const id = (this).attr("data-value");
       $.ajax({ url:'connect_data.php',
            type:'GET',
            data:{id: id},
            success: function(html){
               const result = JSON.parse(html);
               console.log( typeof( result ) );
               console.log( result[0] );
               console.log( result[0].subtitle );
               console.log( typeof( result[0].subtitle ));
           },
           error: function(e){
              alert(e.responseText);
           } ,
           return false;
    });

https://i.sstatic.net/RFgQ9.jpg

Answer №1

Unclear about the reference to $(this), however, there is an alternative way to obtain the values of the two form inputs:

var xml_value = $('input[name="xml"]').val();
var url_value = $('input[name="url"]').val();

It would be helpful to see more of your code related to how data is being retrieved and sent in order to pinpoint where the issue may lie.

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

Dynamically inserting templates into directives

I've been attempting to dynamically add a template within my Angular directive. Following the guidance in this answer, I utilized the link function to compile the variable into an HTML element. However, despite my efforts, I haven't been success ...

Puppeteer for optimizing websites with lazy loading image functionality

My current project involves data scraping from a real estate website (). I've been able to extract all the listing information successfully, except for the images (image links/src). Essentially, after a few images, what I get is just garbage. I delved ...

Utilizing Angular 4 alongside ng-sidebar to incorporate the class "right"

Just started using ng-sidebar in my Angular 4 project, but I'm a bit lost on where to place the "ng-sidebar--right" class. Could someone please guide me through this small issue (I'm new to this, so apologies in advance). Here's a snippet of ...

Using PHP and DOJO to transfer HTML via JSON

My data store is currently querying a database and outputting JSON in the following format: $data[] = array('id' => $i, 'prod_id' => $product_id, 'link' => $link); I am curious about how to include a link using the ...

Steps for creating a mandatory tag description

I am a newcomer to the world of WordPress, and my goal is to make a tag's description a required field on my custom theme for WordPress 4.5.2. I have attempted three different approaches, all of which have been unsuccessful. I would greatly appreciat ...

Disable menu bar | customize menu bar in electronJS

I am developing an Angular application with Electron.js. Due to the specific design requirements of my app, which is browser-based, I do not require or want the default Electron.js menu or menu bar to be displayed. Is there a way to remove it from my app ...

Is there a way to search for packages on npmjs.com using multiple tags?

Is it possible to search for packages on npmjs.com using two or more specific tags? I've tried different search terms like "keywords:webpack+plugin" and "keywords:webpack,plugin", but nothing seems to work. keywords:webpack+plugin keywords:webpack,pl ...

Invoke a web service upon the loading of a page within the scope of an AngularJS Framework

My webservice returns a JsonObject and I am calling it in JS using Ajax as shown below : $scope.init = function () { $.ajax({ type: 'GET', timeout: 1000000000, url: serv ...

Utilizing jQuery to automatically populate fields in an Android WebView when loading a URL

I have been able to achieve the desired output by using the following code in JS: mWebView.loadUrl("javascript:{document.getElementsByName('emailaddress')[0].value = '"+username+"'; document.getElementsByName('password')[0].v ...

Leverage NodeJS data within Angular framework

I am working with the following route: Server app.get('/claim/:id', compact.js(['global']), indexController.claim); module.exports.claim=function(req,res){ res.render('claim-note', { title: 'claim', noteId:req. ...

Why does Jquery refuse to accept hyphens in the JSP page?

I received a field from SERVICE that contains a hyphen. For example, first-name (as a JSON object). However, when I attempt to retrieve the value of this field in my JSP file, I encounter a script error. Can you please advise me on how to properly access ...

Would you like to learn how to display the value of a different component in this specific Angular 2 code and beyond

Hey there, I need your expertise to review this code and help me locate the issue causing variable "itemCount" to not display any value in about.component.html while everything works fine in home.component.html. I am attempting to only show "itemCount" in ...

Unable to modify the textures of objects in three.js by pressing a key

I am attempting to switch materials for a .obj loaded model when a key is pressed, but I am running into an issue where only the first element in the material array is being used. I have double-checked that my loop is functioning correctly. Check out the ...

Tips for loading nested JSON data into an Angular Material dropdown list

My task involves extracting data from a JSON object and displaying the difficultyLevel. Despite several attempts, I have been unable to achieve the desired outcome. What changes should be made to the HTML file? const ELEMENT_DATA: data = { questions ...

Combine the elements by using a computed item mapping

I want to verify that all elements in an array are of the type Item. However, once I implement this, the splice method stops functioning properly. This is my current approach: computedItems: { get() { //return this.modelValue; retu ...

Using ExpressJS to pass a variable from a .js file to index.html

I need assistance with integrating [email protected] I am trying to access a variable from main.js in index.html Here is the code in main.js: const express = require('express') const app = express() var router = express.Router() app.use(& ...

In the process of attempting to upload a .tsv file through the front end interface, I am encountering a challenge as the file remains stored on my server. What is the

I've got a function set up on my Express server that sends a file dependent on D3.JS. app.get('/dashboard', function(req, res) { var timestamp = utility.timestamp(); console.log('[' + timestamp + '] Request made to rend ...

In IE8, dynamically loaded CSS does not take effect on dynamically loaded JavaScript views

Concerns have been raised about possibly duplicating this question, especially since it has taken more than an hour to find a solution. The current scenario involves: A widget that requires dynamic loading of CSS Usage of Sammy.js and .ejs for views, wh ...

A more straightforward approach to parsing JSON data from various services using Swift

Scenario Overview In my current setup, I have a struct that is capable of decoding JSON using the Decodable protocol, making it versatile for handling various responses. Each type of response has its own enum conforming to CodingKey. Illustrative Example ...

How to programmatically close a Bootstrap modal without using jQuery in JavaScript

Is there a way to make it so that I can close a Bootstrap modal with just one click instead of having to double click? Thanks! This is the code I'm currently using to close the Bootstrap modal using JavaScript: // To Close Modal document.getE ...