开发者

Javascript Objects & Netflix OData jsonp results

开发者 https://www.devze.com 2023-03-29 08:09 出处:网络
I am new to working with Javascript objects and jsonp. Basically, here\'s my problem. I am sending the following request to Netflix Odata service:

I am new to working with Javascript objects and jsonp. Basically, here's my problem. I am sending the following request to Netflix Odata service:

http://odata.netflix.com/v2/Catalog/Genres%28%27TV%20Animated%20Comedies%27%29/Titles?$filter=Instant/Available%20eq%20true&$inlinecount=allpages&$top=5&$callback=callback&$format=json

This returns the following results:

callback({-
        d: {
            -
            results: [
                +
                { … }
                +
                { … }
                +
                { … }
                +
                { … }
                +
                { … }
            ]
            __count: "80"
        }
    });

I can easily access the results with this lines of code in my callback function like this:

function callback(result) {
    movies = result["d"]["results"];
    alert(movies.length);
}

When I remove the inlinecount parameter, the following is the result:

callback({-
    d: [
        +
        { … }
        +
        { … 开发者_Go百科}
        +
        { … }
        +
        { … }
        +
        { … }
    ]
});

However, when I try to access the results using these lines of code:

function callback(result) {
    movies = result["d"];
    alert(movies.length);
}

I get "undefined" from the alert. How do I access the results?


I was actually able to get this to work. I shortened the request to the Netflix server to only include the top 5 results for the sake of this question, but in my original code, I was returning the maximum results from the server which is sent with a paging element. Apparently, I was not handling the paging element that was being sent from the Netflix server. This caused the error I was receiving.

0

精彩评论

暂无评论...
验证码 换一张
取 消