I try to store the result of JSON webservice into a List view.
I create my request in javascript but my readyState
value is always 1
and never change. I don't understand what is wrong.
This is my output:
Ready state changed to : 1
import QtQuick 2.0
import Ubuntu.Components 1.1
import Ubuntu.Components.ListItems 0.1 as ListItem
/*!
\brief MainView with a Label and Button elements.
*/
MainView {
// objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView"
// Note! applicationName needs to match the "name" field of the click manifest
applicationName: "com.ubuntu.developer.username.gms"
/*
This property enables the application to change orientation
when the device is rotated. The default is false.
*/
//automaticOrientation: true
// Removes the old toolbar and enables new features of the new header.
useDeprecatedToolbar: false
width: units.gu(100)
height: units.gu(75)
PageStack {
id: pageStack
Component.onCompleted: push(page0)
Page {
id: page0
title: i18n.tr("Index")
visible: false
Column {
anchors.fill: parent
ListItem.Standard {
text: i18n.tr("View history")
onClicked: pageStack.push(page1)
progression: true
}
ListItem.Standard {
text: i18n.tr("External page")
onClicked: pageStack.push(Qt.resolvedUrl("MyCustomPage.qml"))
progression: true
}
}
}
Page {
title: "Rectangle"
id: page1
visible: false
Rectangle {
width: 320
height: 480
ListView {
id: view
anchors.fill: parent
delegate: Text {
anchors.fill: parent
width: view.width
Text { text: "ttile: " + modelData.title }
Text { text: "iconeSource: $" + modelData.media.m }
}
function request() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
console.log("Ready state changed to : " + xhr.readyState +" \n");
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
console.log('HEADERS_RECEIVED')
} else if(xhr.readyState === XMLHttpRequest.DONE) {
console.log('DONE')
var json = JSON.parse(xhr.responseText.toString())
view.model = json.items
}
}
xhr.open("GET", "http://api.flickr.com/services/feeds/photos_public.gne?format=json&nojsoncallback=1&tags=munich");
xhr.send();
}
Component.onCompleted: {
request();
}
} // listView
} // rectangle
} // page
}
}
Normaly I should go inside onreadystatechange function many time...
PS : I have add "networking" permission in app.apparmor
{
"policy_groups": [
"networking"
],
"policy_version": 1.2
}
Try changing the following line:
...to:
Note the true argument given to the async parameter. There's a good chance the synchronous nature of your call is causing major issues.