【发布时间】:2016-12-29 12:30:41
【问题描述】:
我正在尝试通过此调用将新创建的数据发布到我的 json 数据库中
function sendtovenaarData(url){
$.ajax({
url: "http://localhost:3000/" + url,
type: 'POST',
data:
{
voornaam: $("#voornaam").val(),
achternaam: $("#achternaam").val(),
beroep: $("#beroep").val(),
adres:{
streetAddress: $("#streetAddress").val(),
city: $("#city").val(),
state: $("#state").val(),
zip: $("#zip").val()
},
haardplaats: $("#haardplaats").val(),
favoriete_quote: $("#favoriete_quote").val()
}
}).done(function () {
console.log("data added");
location.reload();
}).fail(function (xhr, message, error) {
console.log(xhr, message, error);
});}
我想像图片中的顶部一样保存它,但它像底部一样保存在这附近吗? image of saved json
我已经尝试创建一个变量并将地址放入其中,但它不起作用。感谢您的帮助
【问题讨论】:
-
在添加到
data键之前尝试使用JSON.stringify -
使用
JSON.stringify() -
所以不是您传递的任何数据,而是仅保存
hello吗?
标签: javascript json ajax