Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.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 将更新的HTML表值返回到Views.Py_Javascript_Html_Django - Fatal编程技术网

Javascript 将更新的HTML表值返回到Views.Py

Javascript 将更新的HTML表值返回到Views.Py,javascript,html,django,Javascript,Html,Django,嗨,我有一个html表,它的值最初是从数据库中提取的。它们是可编辑的,如果用户更新了值,我希望能够将更新后的值返回到Views.py,然后从那里将更新后的值保存回数据库。例如,我有下表: <table> <tr> <th>A</th> <th>B</th> <th>C</th>

嗨,我有一个html表,它的值最初是从数据库中提取的。它们是可编辑的,如果用户更新了值,我希望能够将更新后的值返回到Views.py,然后从那里将更新后的值保存回数据库。例如,我有下表:

<table>

            <tr>
                <th>A</th>
                <th>B</th>
                <th>C</th>
                <th>D</th>
                <th>E</th>
                <th>F</th>
            </tr>

                {% for x in VAR %}

                    <tr>
                        <td>Yes</td>
                        <td>{{ x }}</td>
                        <td><div contenteditable>{{ x.a }}</div></td>
                        <td><div contenteditable>{{ x.b}}</div></td>
                        <td><div contenteditable>{{ x.c}}</div></td>
                    </tr>

                {% endfor %}

</table>

A.
B
C
D
E
F
{VAR%中x的%s}
对
{{x}
{{x.a}}
{{x.b}}
{{x.c}}
{%endfor%}
例如,如果他们更新x.a,我想将新值返回到视图


当我尝试POST请求时,我返回一个空值/空列表。如何将更新后的值返回到我的Views.py?

为此,您需要一些javascript。为所有contenteditable div设置一个
input
change处理程序,并将数据打包到
POST
请求中。在jquery中,这大约是:

$('div[contenteditable]').on('input', function(){
    $.post('/setData', {k:this.id, v:this.innerText});
});
(从内存中写入——可能不完全正确)