I'm trying to get movie data for BlackBerry 10 apps. I don't know where I'm making a mistake. Please, can you help me? Thank you all.
import bb.cascades 1.4
Page {
onCreationCompleted: {
sendRequest();
}
function sendRequest() {
var data = "{}";
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://api.themoviedb.org/3/search/movie?include_adult=false&page=1&query=hulk&language=en-US&api_key=YOUR_API_KEY_HERE");
xhr.send(data);
}
}
You need to use the
onreadystatechangeEventHandler. Also, you don't need to pass data when making aGETrequest. I have removed thewithCredentialsline as it isn't needed in this example.You can learn more on
XMLHttpRequesthere : https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequestHere's an example of using
XMLHttpRequestI've made a long time ago : https://github.com/RodgerLeblanc/Markup/blob/master/assets/main.qml