Jquery 将html中已编辑的表转换为json,并发送到django

Jquery 将html中已编辑的表转换为json,并发送到django,jquery,json,ajax,django,Jquery,Json,Ajax,Django,我有一个contenteditable=“true”表作为html的一部分。我希望用户能够编辑该表,并单击按钮发送更新的数据,这些数据将把表转换为JSON,稍后我将用python将其展开为数据帧。到目前为止,我已经找到了获取JSON的方法: <button onclick="table2json()"> JSon </button> <script> function table2json(){ var myJSON =JSON.stringify(m

我有一个
contenteditable=“true”
表作为html的一部分。我希望用户能够编辑该表,并单击按钮发送更新的数据,这些数据将把表转换为JSON,稍后我将用python将其展开为数据帧。到目前为止,我已经找到了获取JSON的方法:

<button onclick="table2json()">
 JSon
</button>
<script>
 function table2json(){ 
 var myJSON =JSON.stringify(makeJsonFromTable("dataframe"))
 //return console.log(myJSON)
 }
</script>
但是我在jQuery中实际写了什么呢

谢谢大家!

$.ajax({
 url: '/saveData' // endpoint,
 dataType: 'json', // type of data
 data: myJson // data to send,
 method: 'POST'
})
.done(function(response) {
  // do stuff with server response
})
.fail(function(error) {
  // show notification
});

关于jQuery中ajax的更多信息

需要添加的一点是,
/saveData
应该在django应用程序的
url.py
中定义,并且必须指向
gettable
函数。
$.ajax({
 url: '/saveData' // endpoint,
 dataType: 'json', // type of data
 data: myJson // data to send,
 method: 'POST'
})
.done(function(response) {
  // do stuff with server response
})
.fail(function(error) {
  // show notification
});