我想发送一个ajax请求,在我的圈子的鼠标悬停事件中加载一些数据(json),并在我的圈子上的pup up窗口中显示服装数据。 任何想法如何处理这个?
r.circle(100, 100, 50).attr({
fill: "CadetBlue",
stroke: "black"
}).mouseover(function (e) {
var request = new XMLHttpRequest();
});
答案 0 :(得分: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();
});