Почему XMLHttpRequest отправляет только & ldquo; соединение с сервером установлено & ldquo; в атрибуте readyState?

Я пытаюсь сохранить результат веб-службы JSON в виде списка.

Я создаю свой запрос в javascript, но мое readyState значение всегда 1 и никогда не изменяется. Я не понимаю, что не так.

Это мой вывод:

Состояние готовности изменено на: 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 Я должен войти в onreadystatechange функция много времени ...

PS: Я добавил «сетевое» разрешение в app.apparmor

{
    "policy_groups": [
        "networking"
    ],
    "policy_version": 1.2
}
1
задан 11 December 2014 в 20:45

0 ответов

Другие вопросы по тегам:

Похожие вопросы: