logo
Tags down

shadow

access data using api


By : Adam Czajkowski
Date : May 07 2020, 10:03 AM

I setting up a little script for my personal use to understand Ajax and jQuery by testing the Nike API to have information about any products.

I do little loop to have information on the actual API but i'm stuck when i want to pass the seconds objects

function getSnkrs() {
    var test = $('.test');
    $.ajax({
        type: "GET",
        url: "https://api.nike.com/product_feed/threads/v2/?filter=marketplace%28FR%29&filter=language%28fr%29&filter=channelId%28010794e5-35fe-4e32-aaff-cd2c74f89d61%29&&filter=exclusiveAccess%28true%2Cfalse%29",
        async: false,

        success: function(data) {
            for (i = 0; i < 10; i++) {
                for (y = 0; y < 10; y++) {

                //<br><img src="'+ data._embedded.objects[i].publishedContent[i].nodes[i].properties[i].portraitURL[i].url +'"style="width: 20%; height=auto;><br>
                test.append('<br><a>'+    data.objects[i].publishedContent[y].marketplace   +'</a><br>');

            }
        }
    }
});

}

On the console I have this :

jquery-1.9.1.js:7985 Uncaught TypeError: Cannot read property 'marketplace' of undefined
at Object.success (script.js:36)
at fire (jquery-1.9.1.js:1037)
at Object.fireWith [as resolveWith] (jquery-1.9.1.js:1148)
at done (jquery-1.9.1.js:8074)
at callback (jquery-1.9.1.js:8598)
at Object.send (jquery-1.9.1.js:8604)
at Function.ajax (jquery-1.9.1.js:7978)
at getSnkrs (script.js:26)
at HTMLDocument. (script.js:3)
at fire (jquery-1.9.1.js:1037)

I like to have the element ' marketplace' if someones can help me thank you ! :

{
    "pages": {
    "prev": "",
    "next": "/product_feed/threads/v2?filter=marketplace%28FR%29&filter=language%28fr%29&filter=channelId%28010794e5-35fe-4e32-aaff-cd2c74f89d61%29&filter=exclusiveAccess%28true%2Cfalse%29&anchor=50",
    "totalPages": 26,
    "totalResources": 1258
    },
    "objects": [
    {
        "id": "a6ecf9f2-8f73-4d1a-b761-5e0772153fdb",
        "channelId": "010794e5-35fe-4e32-aaff-cd2c74f89d61",
        "channelName": "SNKRS Web",
        "marketplace": "FR",
        "language": "fr",
        "lastFetchTime": "2019-08-13T15:13:15.879Z",
        "publishedContent": {
        "preview": false,
        "marketplace": "FR",
Answer :

i see that publisherContent is not an array? (correct me if i m wrong), it is a json object. try to remove the "y" looping:

for (var i = 0; i < data.objects.length; i++) {

//<br><img src="'+ data._embedded.objects[i].publishedContent[i].nodes[i].properties[i].portraitURL[i].url +'"style="width: 20%; height=auto;><br>
test.append('<br><a>'+ data.objects[i].publishedContent.marketplace   +'</a><br>');
}


Share : facebook icon twitter icon
Related Posts Related Posts :
  • clear array after form submit
  • pass url variable to javascript
  • div position fixed css
  • add horizontal line between two div
  • disable toggle button css
  • css fixed line height
  • background image not working
  • table cell border
  • text line break css
  • overlay div on div
  • text direction rtl css
  • javascript convert string to an object
  • bind inner div click to outer div
  • jquery ajax oncomplete
  • how to use promise in for loop
  • jquery get element using variable
  • javascript send textbox value
  • pass div class content to another class or id
  • css new line after element
  • css calc not working properly
  • link disabled jquery
  • sql join table to subquery
  • MS Access SQL Issue with OR AND Operators
  • set textarea value using php
  • php merge two arrays into one
  • php form with google captcha
  • update current row in php
  • php date format mysql
  • mysql pdo select query
  • php function return an array
  • PHP mysqldump database to sql file
  • display image query
  • php create array using foreach loop
  • associative array php
  • group_concat in mysql laravel
  • php array_push empty
  • mysql on update cascade not working
  • pdo insert prepared statement
  • mysql insert ignore vs on duplicate key
  • mysql insert into existing row
  • mysql multi insert query
  • mysql group by show all rows
  • php change profile image
  • combine multiple arrays into one array php
  • how to sum values in an array
  • how to get sum of the total time
  • How to Create Facebook live stream without notification using API ?
  • on button click make div visible
  • css affect another element on hover
  • insert line after paragraph word
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org