1.ajax.js 

ajax.js
function createXMLHttpRequest() {
    var req = null;

    try {
        req = new XMLHttpRequest();
        if (typeof req.overrideMimeType !== "undefined") {
            req.overrideMimeType("text/xml");
        }
    } catch (ex) {
        req = null;
    }

    return req;
}

function loadXMLDoc(req, url, parameters, onSuccess, onFailed) {
    req.onreadystatechange = function() {
        processStateChange(req, onSuccess, onFailed);
    };
    req.open("POST", url, true);
    req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    req.send(parameters);
}

function processStateChange(req, onSuccess, onFailed) {
    if (req.readyState === 4) {
        if (req.status === 200) {
            onSuccess(200, req.responseText);
        } else {
            onFailed(req.status, null);
        }
    }
}


2.qml中调用

import "ajax.js" as AjaxScript

Rectangle{
    。。。
}

function do(){
    var url = 'http://www.some.com/portal';
    var parameters = 'method=test&arg1=1';
    var req = AjaxScript.createXMLHttpRequest();
    AjaxScript.loadXMLDoc(req, url, parameters,
                          function(code,text){
                              var Response = eval('(' + text + ')');
                              //Response.value1
                              //Response.value2
                              //Response.value2.value1
                              //.......
                          },
                          function(code,text){
                              //数据请求失败
                          });

}