0

我想发送一个 ajax 请求以在我的圈子的鼠标悬停事件上加载一些数据(json),并在我的圈子上方的小狗窗口中显示服装数据。知道如何处理吗?

r.circle(100, 100, 50).attr({
    fill: "CadetBlue",
    stroke: "black"
}).mouseover(function (e) {
    var request = new XMLHttpRequest();
});
4

1 回答 1

1

您可以像这样执行 ajax 查询:

r.circle(100, 100, 50).attr({
    fill: "CadetBlue",
    stroke: "black"
}).mouseover(function (e) {
    var httpRequest = new XMLHttpRequest();
    httpRequest.onreadystatechange = function() {
        if (httpRequest.readyState === 4) {
            if (httpRequest.status === 200) {
                var msg = JSON.parse(httpRequest.responseText);

                // do stuff, for example show a popup

            } else {

                // fail

            }
        }
    };
    httpRequest.open('GET', url);
    httpRequest.send();
});
于 2012-05-27T10:40:24.203 回答