Created
March 9, 2012 03:41
-
-
Save diorahman/2004896 to your computer and use it in GitHub Desktop.
XMLHttpRequest on QML (GET)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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