当使用ajax发布要表达的数据时,我一直收到一个意外的令牌。我检查了变量以确保它们没有未定义,所以我不确定我哪里出错了。
functions.js
$('#saveClause').click(function () {
var username = document.getElementById('postUserName').innerText;
var clauseTitle = document.getElementById('modalTitle').innerText;
var clauseDescription = document.getElementById('modalDescription').innerText;
var clauseText = document.getElementById('modalText').innerText;
//alert(username + " " + clauseTitle + " " + clauseDescription + " " + clauseText);
$.ajax({
url: "/classes/updateAssignment",
type:"POST",
dataType:"json",
data: {
username: username,
title: clauseTitle,
description: clauseDescription,
text: clauseText
},
contentType: "application/json",
cache:false,
timeout: 5000,
complete: function() {
console.log("Process Complete");
},
success: function(data) {
console.log("Process Success");
console.log(data);
},
error: function() {
console.log("Process Error");
},
});
})
classes.js route
router.post('/updateAssignment', function (req, res) {
console.log(req.body.username)
console.log(req.body.title);
console.log(req.body.description);
console.log(req.body.text);
res.contentType('json');
res.send({
some: JSON.stringify({
response: 'json'
})
});
});