我正在尝试使用Airtable作为我的项目中提交表单的后端。但是,我似乎不能集成API,我也不知道问题所在。我使用的是React和axios。
我对JS和Airtable都很陌生。
以下是我的错误代码:
提交表单后浏览器出错:
Airtable错误:{“error”:{“type”:“INVALID_REQUEST_MISSING_FIELDS”,“消息”:“在请求正文中找不到字段”字段“}}
有人能告诉我我做错了什么吗?提前谢谢你!
下面是我的代码:
var form = document.querySelector("#bize-ulasin");
if(form) {
form.addEventListener("submit", function(event) {
event.preventDefault();
axios.post(airtable_write_endpoint,
{
"Content-Type": "application/json"
} ,
{
"fields": {
"AdSoyad": document.getElementById("#Ad-Soyad"),
"Email": document.getElementById("#Email"),
"Telefon": document.getElementById("#Telefon"),
"Konu": document.getElementById("#Konu"),
"Mesaj": document.getElementById("#Mesaj"),
"Ortam": "Websitesi"
}
})
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log(error);
})
})
};发布于 2018-12-18 00:48:12
这看起来像是你如何组织你的axios调用的错误。看起来您实际上是在POST调用中传递{"Content-Type": "application/json"}作为有效负载,而不是第二个参数。您应该能够通过re-ordering the parameters in your call进行修复
axios.post(airtable_write_endpoint,
{
"fields": {
"AdSoyad": document.getElementById("#Ad-Soyad"),
"Email": document.getElementById("#Email"),
"Telefon": document.getElementById("#Telefon"),
"Konu": document.getElementById("#Konu"),
"Mesaj": document.getElementById("#Mesaj"),
"Ortam": "Websitesi"
},
}
{
headers: { "Content-Type": "application/json"}
})
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log(error);
})
})希望这能有所帮助!
发布于 2019-07-30 19:22:46
Airtable有一个JavaScript package,它可以让您以编程方式访问任何Airtable工作表中的任何基础。Airtable还会为您的bases生成完整的API文档。您可以在以下位置找到您的接口:https://airtable.com/api

选择一个库,您将看到一个完整的API,其中包含示例、调用和所有内容。
它显示了完整的JavaScript示例:
EXAMPLE USING ENVIRONMENT VARIABLE
# Shell:
$ export AIRTABLE_API_KEY=YOUR_API_KEY
# Node:
const base = require('airtable').base('YOUR_AIRTABLE_BASE');
EXAMPLE USING CUSTOM CONFIGURATION
var Airtable = require('airtable');
Airtable.configure({
endpointUrl: 'https://api.airtable.com',
apiKey: 'YOUR_API_KEY'
});
var base = Airtable.base('YOUR_AIRTABLE_BASE');发布于 2020-05-13 08:15:04
"AdSoyad": document.getElementById("idname")选择相关的html元素,没有值
你可以在没有id标签(#)的情况下用"AdSoyad": document.getElementById("Ad-Soyad").value解决这个问题,因为你已经编写了不需要#的getElementById
https://stackoverflow.com/questions/53508398
复制相似问题