从javascript到服务器
我有这个代码,它允许你上传一个图像到画布上,并在画布上标记出片段。双击画布时,段的坐标将添加到数组中。是否可以将此数组从javascript到服务器,javascript,django,Javascript,Django,我有这个代码,它允许你上传一个图像到画布上,并在画布上标记出片段。双击画布时,段的坐标将添加到数组中。是否可以将此数组segmentList写入JSON文件或发送到django服务器?还有什么地方可以让我读到这个吗?提前谢谢 $("#imageCanvas").click(function(e) { var x = e.offsetX var y = e.offsetY // Adding 'X' and 'Y' values to the resp
segmentList
写入JSON文件或发送到django服务器?还有什么地方可以让我读到这个吗?提前谢谢
$("#imageCanvas").click(function(e)
{
var x = e.offsetX
var y = e.offsetY
// Adding 'X' and 'Y' values to the respective list
xList.push(x);
yList.push(y);
var coods = document.getElementById("coods");
coods.innerHTML = 'X: ' + x + ' Y: ' + y;
})
$('#imageCanvas').on('dblclick', function() {
first = new Segmentation();
xList.pop()
yList.pop()
first.X = xList;
first.Y = yList;
segmentList.push(first);
if(first.X == "" && first.Y == "")
{
alert("No points seleected!")
}
else if(first.X.length < 3 && first.Y.length < 3)
{
alert("Please select at least more than 3 points!")
}
else
{
for( i=0; i< first.X.length; i++)
{
if(i<first.X.length-1)
{
console.log(first.X)
context.beginPath();
xpos = first.X[i];
console.log(first.X[i])
ypos = first.Y[i]
var xpos1 =first.X[i+1]
var ypos1 =first.Y[i+1]
}
if(i==first.X.length-1)
{
xpos = first.X[i]
ypos = first.Y[i]
var xpos1 =first.X[0]
var ypos1 =first.Y[0]
}
context.moveTo(xpos, ypos)
context.lineTo(xpos, ypos)
context.lineTo(xpos1, ypos1)
context.strokeStyle= "red" ;
context.stroke();
}
}
xList = [];
yList = [];
});
$(“#图像画布”)。单击(函数(e)
{
var x=e.offsetX
变量y=e.offsetY
//将“X”和“Y”值添加到相应的列表中
xList.push(x);
yList.push(y);
var coods=document.getElementById(“coods”);
coods.innerHTML='X:'+X+'Y:'+Y;
})
$('#imageCanvas')。在('dblclick',function()上{
第一个=新分段();
xList.pop()
yList.pop()
第一,X=xList;
第一,Y=yList;
分段列表。推送(第一);
if(first.X==“”&first.Y==“”)
{
警报(“未选择任何点!”)
}
否则如果(第一个X轴长度<3和第一个Y轴长度<3)
{
警告(“请选择至少3点以上!”)
}
其他的
{
对于(i=0;i