Unpredictable Results with JSON Data

Can anyone shed some light on why all my JSON data is showing up as Undefined? Here is the JSON snippet in question:

{"273746":[{"name":"Darius's Wizards","tier":"GOLD","queue":"RANKED_SOLO_5x5","entries":[{"playerOrTeamId":"273746","playerOrTeamName":"Magnanimous","division":"V","leaguePoints":0,"wins":19,"losses":15,"isHotStreak":false,"isVeteran":false,"isFreshBlood":false,"isInactive":false}]}]}

And here is the JavaScript code I'm using to process this data:

Note: In the code snippet, i /sumID is 273746 and s is 'oce' in adherence to Riot API guidelines.

function statsLookUp(i,s) {

    $.ajax({

    url: 'https://oce.api.pvp.net/api/lol/' + s + '/v2.5/league/by-summoner/' + i + '/entry?api_key=',
        type: 'GET',
        dataType: 'json',
        data: {

        },
     success: function (json) {
        //all json goes here

        var sumID = i;

        leagueName = json[sumID].name;
        leagueTier = json[sumID].tier;
        leagueDiv = json[sumID].entries.division;
        leagueLoss = json[sumID].entries.losses;
        leagueWin = json[sumID].entries.wins;


           document.getElementById("sLeague").innerHTML = leagueName;
           document.getElementById("sTier").innerHTML = leagueTier;
           document.getElementById("sDivision").innerHTML = leagueDiv;
           document.getElementById("sWins").innerHTML = leagueWin;
           document.getElementById("sLosses").innerHTML = leagueLoss;


        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert("error getting Summoner data!");
        }
    });
}

Despite my efforts, everything keeps showing up as undefined. Can't seem to pinpoint the issue at hand :/

Answer №1

Simply implement these modifications, and your code should work perfectly:

leagueName = json[sumID][0].name;
leagueTier = json[sumID][0].tier;
leagueDiv  = json[sumID][0].entries[0].division;
leagueLoss = json[sumID][0].entries[0].losses;
leagueWin  = json[sumID][0].entries[0].wins;

Below is the neatly formatted JSON Data:

{
   "273746":[
      {
         "name":"Darius's Wizards",
         "tier":"GOLD",
         "queue":"RANKED_SOLO_5x5",
         "entries":[
            {
               "playerOrTeamId":"273746",
               "playerOrTeamName":"Magnanimous",
               "division":"V",
               "leaguePoints":0,
               "wins":19,
               "losses":15,
               "isHotStreak":false,
               "isVeteran":false,
               "isFreshBlood":false,
               "isInactive":false
            }
         ]
      }
   ]
}

Hopefully, this information proves to be useful for you.

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

Executing Ajax requests with callbacks in JavaScript/jQuery

I'm facing an issue where my functions are executing before Ajax requests (first fetching local JSON, then retrieving data from an online resource) have completed. For example, I want countTheMovies to run only after all the necessary information is ...

Monitoring individual elements of an array within an Angular service

Is there a way to monitor changes in an array element within a service? Let's consider the following scenario with CartController and ProductListService. Within the ProductListService, data is fetched as follows: /** * Fetch all the products in us ...

Avoiding scrolling when a button (enveloped in <Link> from react-scroll) is pressed in React

Currently, I am implementing the smooth scroll effect on a component using react-scroll. However, adding a button inside the component to create a favorite list has caused an issue where the smooth scroll effect is triggered upon clicking the button. Is ...

Adding elements within a loop using jquery

I am currently working on adding a toggle button using Javascript. I want to include three span tags inside it as well. To achieve this, I am creating a span variable and attempting to append it within a basic FOR loop that iterates 3 times. Below is the ...

Github Pages is experiencing a bit of a hiccup with 400 errors due to a problem with the manifest.json file

I'm encountering some issues while trying to deploy my Github Pages website at . The errors I keep facing are as follows: - Failed to load resource: the server responded with a status of 400 () - manifest.json:1 Failed to load resource: the server ...

I successfully managed to ensure that the splash screen is only displayed upon the initial page load. However, I am now encountering an issue where it fails to load again after I close the page. Is there any possible solution

After successfully implementing a splash screen that only plays once on page load, I encountered an issue. When I close the tab and revisit the page, the splash screen no longer plays. Is there a way to fix this problem? Perhaps by setting a time limit for ...

`sendNodejs header not being transmitted during connection``

My nodejs application utilizes stomp to connect to a server using websockets. However, I am encountering an issue where the application is failing to send the headers that I have specified. Despite referring to clear documentation and examples on how to in ...

Leverage ActiveModel::Serializers for incorporating two primary JSON arrays

I am attempting to send my front-end application JSON data structured like this: { facilities: [ {id: 5, name: 'Happy Days Ranch', location: { address: '1424 Pastoral Lane', zipcode: '25245'}, instructor_ids: [2, 4, 9] ...

Is your website's Google analytics event tracking not giving you the feedback you need

Here's what I'm trying to achieve in the code below: Set up Google Analytics on the page Add a jQuery click event based on specific query strings and domain characters Trigger a Google Analytics tracking event with the click event Implement cod ...

Searching for values in nested arrays using lodash.find

Presented below is an array where I aim to employ lodash for item search: [ { "itemA": "apple", "itemB": [ { "itemC": "1", "itemD": "red apple" }, { "itemC": "2", "itemD": "green apple" }, ...

Meteor.js in conjunction with ScrollMagic TweenMax.to

Having trouble getting Meteor template.rendered to work with ScrollMagic I am trying to make this code function properly. if (Meteor.isClient) { Meteor.startup(function () { scrollMagicController = new ScrollMagic(); Template.StartAnimatio ...

When trying to reference "this" and store it in a variable, it appears as undefined. However, DevTools show that it is actually defined

I've encountered an unusual situation in my React app involving the binding of "this" - I have a function within a component named "App" that is located in a separate file. In the main file, I've bound the "this" command to it. What's puzzl ...

Error: Unable to retrieve the value as the property is null

I'm a beginner in jQuery and I'm attempting to create a login form that displays a message when the user enters a short username. However, despite my efforts, the button does not trigger any action when clicked. Upon checking the console, it indi ...

How to Incorporate an Anchor Link into a Div as well as its Pseudo Element using CSS, Javascript, or jQuery

How can I make both the menu item and its icon clickable as a link? When either is clicked, the link should work. Here is a CodePen example: http://codepen.io/emilychews/pen/wJrqaR The red square serves as the container for the icon that will be used. ...

Sort an array of objects by matching string properties with elements from another array

If the array of objects is represented by rows and wantedBrands consists of an array of strings, how can I achieve a specific result? let rows = [ { name: "Russia", brands: ['XM1', 'XM2', 'XM3'] }, ...

The setTimeout function fails to behave as intended when used in conjunction with synchronous ajax

Within my code, I have a function that is being invoked multiple times due to iterating through an array of length n and creating 'Plants' with synchronous ajax calls. These calls involve querying the Google Maps API, so it is crucial to throttle ...

Using JQuery to create a button inside a Modal dialog box

My goal is to select a row within a Table that is located inside a Modal window, and then have a button ('newBtn') within that Modal window trigger a post request to the server with the selected id of the row. However, the issue I am encountering ...

Issues encountered with the functionality of face-api and tensorflow.js within the browser

I've been trying to execute this example in the browser Check out the example here Specifically looking at this code snippet <!DOCTYPE html> <html> ... (Contents of the code snippet) ... </body> </html> Unfortunately, I&apos ...

Is it possible for a jQuery ajaxSuccess function to detect an AJAX event in a separate JavaScript file? If it is, what steps am I missing?

I've been attempting to initiate a function following an ajax event. I have been informed that despite the ajax event occurring in a different file (on the same server, if that makes a difference) and that the file is javascript, not jquery, "Ajaxsucc ...

Errors during the compilation of Webgl shaders in the Google Chrome browser

Currently, I am in the process of learning three.js by following this tutorial: . Despite the tutorial working well, I have encountered errors in my own code which seem like this: ERROR: 0:26: 'nuniform' : syntax error Three.js:325 precision hi ...