Skip to content

Instantly share code, notes, and snippets.

@TheCompez
Created January 10, 2022 15:09
Show Gist options
  • Save TheCompez/1f94455136a38ea622ec493760d5bba1 to your computer and use it in GitHub Desktop.
Save TheCompez/1f94455136a38ea622ec493760d5bba1 to your computer and use it in GitHub Desktop.
import QtQuick
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
function jsonApiRequest() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
print('HEADERS_RECEIVED')
} else if(xhr.readyState === XMLHttpRequest.DONE) {
var json = JSON.parse(xhr.responseText.toString())
console.log("UserId: " + json.userId)
}
}
xhr.open("GET", "https://jsonplaceholder.typicode.com/todos/1");
xhr.send();
}
Component.onCompleted: {
jsonApiRequest();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment