Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从javascript到服务器_Javascript_Django - Fatal编程技术网

从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