我正在为一个项目使用wagtail/django,并试图对制表器进行ajax调用。我现在有这个
var table = new Tabulator("#example-table", {
ajaxURL:"http://localhost:8000/api/v2/people/?fields=*", //ajax URL
ajaxConfig:{
method:"get", //set request type to Position
headers: {
"Content-type": 'application/json; charset=utf-8', //set specific content type
},
},
height:"311px",
layout:"fitColumns",
placeholder:"No Data Set",
columns:[
{title:"Name", field:"name", sorter:"string", width:200},
{title:"Date", field:"date", sorter:"string"},
],
});
table.setData();但是我在浏览器中的调试控制台有
Request URL:http://localhost:8000/api/v2/people/?fields=*?
"message": "fields error: unexpected char '?' at position 1"为什么在末尾加了一个问号?如果我在Django Rest页面的末尾添加一个问号,我可以复制相同的错误。
发布于 2020-01-15 19:08:28
添加?是因为这是将附加参数传递给URL的标准方法,而且显然Tabulator不会检查ajaxURL是否已经有参数。您可以通过将fields参数移动到ajaxParams来修复此问题,该参数将与Tabulator可能传递的任何其他参数组合在一起:
var table = new Tabulator("#example-table", {
ajaxURL:"http://localhost:8000/api/v2/people/",
ajaxParams: {'fields': '*'},
ajaxConfig:{
method:"get", //set request type to Position
headers: {
"Content-type": 'application/json; charset=utf-8', //set specific content type
},
},
height:"311px",
layout:"fitColumns",
placeholder:"No Data Set",
columns:[
{title:"Name", field:"name", sorter:"string", width:200},
{title:"Date", field:"date", sorter:"string"},
],
});https://stackoverflow.com/questions/59744767
复制相似问题