Skip to content

Instantly share code, notes, and snippets.

@diorahman
Created March 9, 2012 03:41
Show Gist options
  • Save diorahman/2004896 to your computer and use it in GitHub Desktop.
Save diorahman/2004896 to your computer and use it in GitHub Desktop.
XMLHttpRequest on QML (GET)
var xhr = new XMLHttpRequest();
var item;
function setItem(aitem) {
item = aitem;
}
function abort() {
xhr.abort();
}
function get(params) {
var url = 'http://your-service-url/json/format?params=' + params ;
xhr.open("GET",url,true);
xhr.onreadystatechange = function()
{
if ( xhr.readyState == xhr.DONE )
{
if ( xhr.status == 200 )
{
var jsonObject = JSON.parse(xhr.responseText);
item.ended(jsonObject, source);
}
else
{
item.error();
}
}
}
// if you need to set some headers
// xhr.setRequestHeader()
xhr.send();
item.started();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment