-1

我处于应用程序开发的基本水平。

我想知道如何使用任何新版本的 JQuery 发送和获取这些数据。

我也希望它支持所有浏览器。

我只是在使用简单的 Ajax,但我知道使用 Jquery 是可能的,但我无法弄清楚。

function SendData() {
    var data = "action=check&uid=" + uid + "&fbuid=" + fb_uid + ";
    var url = "http://www.example.com/call.php";
    var ajax = new AJAXInteraction(url, CheckRate);
    ajax.doPost(data);
};

function CheckRate(Content) {
    response = JSON.parse(Content);
    Rate = response.stat.rate;
    document['getElementById']('ERate')['value'] = Rate;
};

function AJAXInteraction(url, callback) {
    var req = init();
    req.onreadystatechange = processRequest;
    function init() {
        if (window.XMLHttpRequest) {
            return new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    function processRequest() {
        if (req.readyState == 4) {
            if (req.status == 200) {
                if (callback) callback(req.responseText);
            }
        }
    }
    this.doGet = function () {
        req.open("GET", url, true);
        req.send(null);
    }
    this.doPost = function (str) {
        req.open("POST", url, true);
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        req.send(str);
    }
};

我能够解决第一部分但仍然不知道休息:

function SendData(){
    dataString = "action=check&uid=" + uid + "&fbuid=" + fb_uid + ";
    url = "http://www.example.com/call.php";
    jQuery.ajax({
        type: "POST",
        url: url,
        data: dataString,
    });
};

我的问题是我将如何阅读回复

function CheckRate(Content) {
    response = JSON.parse(Content);
    Rate = response.stat.rate;
    document['getElementById']('ERate')['value'] = Rate;
};
4

1 回答 1

0
function SendData() {
    dataString = "action=check&uid=" + uid + "&fbuid=" + fb_uid + ";
    url = "http://www.example.com/call.php";
    jQuery.ajax({
        type: "POST",
        url: url,
        data: dataString, // sending data
        success: function (data) {
            CheckRate(data); // receiving data
        }
    });
};

// function body should looks like this
function CheckRate(Content) {
    response = JSON.parse(Content);
    Rate = response.stat.rate;
    document['getElementById']('ERate')['value'] = Rate;
};
于 2012-09-23T09:41:57.750 回答