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.
精彩评论