Snap.ajax(…)
简单的Ajax方法。
参数
url
字符串。URLpostData
对象或字符串。要post的数据。callback
函数。回调函数。scope
对象。回调函数的作用域。
或者
url
字符串。URLcallback
函数。回调函数。scope
对象。回调函数的作用域。
返回值
XMLHttpRequest
。返回XMLHttpRequest对象。
使用
<svg id="svg" width="100" height="100"></svg>
<input id="button" type="button" value="ajax获取填充色">
var svg = Snap("#svg");
var c = svg.paper.circle(50,50,40);
document.getElementById("button").onclick = function() {
Snap.ajax("../_ajax/ajax.php", function(response) {
c.attr({
fill: response.responseText
});
});
};
<?php
echo '#' . rand(0, 9). rand(0, 9). rand(0, 9);
?>