Error printing Owner.screenname and Owner.url (Dailymotion Data API) property value

Asked

Viewed 15 times

0

When running GET for PLAYLIST and VIDEO resources, I had a problem. When running GET on my console, the request correctly returns the values of the Owner.screenname and Owner.url attributes; however, when making the same request by AJAX (jQuery), these values are presented as Undefined (Google Chrome console). Could you tell me where I’m going wrong? I’m using the Dailymotion Data API. I’m calling from http://localhost: 8084 (Apache Tomcat)

Code:

$.ajax({     
    type: "GET",    
    url: "https://api.dailymotion.com/video/x26ezj5?fields=id,title,owner,owner.screenname,owner.url",    
    dataType: "json"  
})  
.done(function(data){    
    console.log(data.id);    
    console.log(data.title);    
    console.log(data.owner);     
    console.log(data.owner.screenname);     
    console.log(data.owner.url);     
})    
.fail(function(jqXHR, textStatus, errorThrown){    
    console.log(jqXHR.status + textStatus + errorThrown);    
})    
.always(function(data) {    
    console.log(data);    
});    

Chrome console:

x26ezj5  
Greetings  
x1fz4ii  
undefined  
undefined  
{id: "x26ezj5", title: "Greetings", owner: "x1fz4ii", owner.screenname: "Dailymotion API", owner.url: "https://www.dailymotion.com/DailymotionAPI"} 

1 answer

0

Using the same code, but in javascript puro, I got results.

Copy and paste this code into the console in the browser and you will see the result.

Turns out you’re giving console.log() in all properties of the object data and where to return undefined is because the property does not exist in the object data

var xhr = new XMLHttpRequest();
var uri = "https://api.dailymotion.com/video/x26ezj5?fields=id,title,owner,owner.screenname,owner.url";

xhr.open("GET", uri, true);

//callback
xhr.onreadystatechange = function () {
    if(xhr.status >= 200 && xhr.status < 300) {         
         const response = JSON.parse(xhr.response);
         console.log(response)
    } else {
         console.log("offline");
    }
};
xhr.send(null);

inserir a descrição da imagem aqui

  • Wagner, thank you for your contribution! I was able to solve by swapping: data.owner.screenname by date["Owner.screenname"] and data.owner.url by date["Owner.url"].

Browser other questions tagged

You are not signed in. Login or sign up in order to post.