1
代わりに次のjqueryコードを翻訳して、フェッチAPIを使用しようとしました。私は空の配列を取得するノードを持つ端末にそれをconsole.log
とき
fetch('/{{user.username}}', {
method: 'PUT',
headers: {
'Content-Type': 'application.json'
},
body: JSON.stringify({
street: document.getElementById("street").value,
city: document.getElementById("city").value,
state: document.getElementById("state").value,
zip: document.getElementById("zip").value
})
}).then(() => {
cancel()
location.reload()
})
}
:
function save() {
$.ajax('/{{user.username}}', {
method: 'PUT',
data: {
street: $('#street').val(),
city: $('#city').val(),
state: $('#state').val(),
zip: $('#zip').val()
},
complete: function() {
cancel()
location.reload()
}
})
}
これは、APIリクエストをフェッチされています。それはPUT
要求を行います。
私は、次のとExpressでそれを処理しようとしています:
app.put('/:username', function (req, res) {
console.log(req.body)
console.log("hello")
var username = req.params.username
var user = getUser(username)
user.location = req.body
saveUser(username, user)
res.end()
})