我有这个脚本。它从SVG收集折线点数据。它将数据打印到控制台。我正在尝试使这些数据作为发布请求发送。
我已经尝试将变量添加到请求中,如您在w: (polylines.strokeWidth)
上看到的
var $ = unsafeWindow.jQuery;
var jQuery = unsafeWindow.jQuery;
// Create request to fetch the SVG file.
xhr=new XMLHttpRequest();
// Tell the request where the file is.
xhr.open("GET", "http://colorillo.com/bxys.inline.svg");
// Add event handler to process the file once it's been fetched.
xhr.addEventListener("load", function() {
// Once the text is available, create an XML parser
// and parse the text as an SVG image.
const xmlDoc = new DOMParser().parseFromString(
this.responseText.trim(),
"image/svg+xml"
);
// xmlDoc.getElements() returns something Array-like, but not an Array.
// This turns it into an Array.
const polylines = Array.from(xmlDoc.getElementsByTagName('polyline'));
console.log(polylines.map(
pl => [
// Parses each 'points' attribute into an array of pairs of numbers
pl.getAttribute('points').split('').map(
pair => pair.split(',').map(x=>+x)
),
// Various stroke information
pl.style.stroke,
+pl.style.strokeWidth,
]
));
$.post("http://colorillo.com/draw.php?ing=_index", {
l: (polylines.map),
w: (polylines.strokeWidth),
c: ("#00ff00"),
o: ("100"),
f: ("1"),
_: ("false")
})
});
xhr.send();
上面的这段代码在Google的控制台中给出了错误。我不知道如何解决这个问题。我只希望它获取折线和strokeWidth的数据,并将它们作为后期请求发送。